[ Prev | Table of Contents | Next ]
Filenames are limited to FILENAME_MAX characters. At most FOPEN_MAX files may be open at a given time.
clearerr
void clearerr(FILE *stream)
fclose
int fclose(FILE *stream)
Returns EOF if error occurs, zero otherwise.
feof
int feof(FILE *stream)
Returns non-zero if EOF is set.
ferror
int ferror(FILE *stream)
Returns non-zero if error exists for 'stream'.
fflush
int fflush(FILE *stream)
Returns EOF if error, zero otherwise. fflush(NULL) flushes all output streams.
fgetc
int fgetc(FILE *stream)
Returns EOF if error.
fgets
char *fgets(char *s, int n, FILE *stream)
Returns s, or NULL if error.
fgetpos
int fgetpos(FILE *stream, fpos_t *ptr)
Records current position in 'stream' in '*ptr'.
fopen
FILE *fopen(const char *filename, const char *mode)
modes: "r" read only "w" write; discard previous contents "a" append "r+" read and write "rb" read (binary) "wb" write (binary) "ab" append (binary) "r+b" read and write (binary)
fprintf
int fprintf(FILE *stream, const char *format, ...)
Returns number of characters printed, or negative result if error. Conversion
specification begins with '%' and ends with conversion character. In between,
there may be (in order):
flags: '-' left justify '+' print with sign ' ' <space> prefix with space if no sign '0' <zero> specifies padding with leading zeros '#' alternate output form numbers: n first number specifies field width '.' period used as separator n second number specifies precision (max characters) m modifier (h - short, l - long, L - long double) format characters: d,i int; signed o int; unsigned octal (without leading zero) x,X int; unsigned hexadecimal u int; unsigned c int; single character s char *; string f double; e,E double; scientific notation g,G double; %e or %f format, depending on value p void *; pointer n int *; number of characters written so far % no argument, print '%' example: fprintf( myFilename, "Results are %d and %6.2f\n", myInt, myReal);
fputc
int fputc(int c, FILE *stream)
Returns c, or EOF if error.
fputs
int fputs(const char *s, FILE *stream)
Returns non-negative result, or EOF if error.
fread
size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream)
Reads from 'stream' into 'ptr' at most 'nobj' objects of size 'size'. Returns
number of objects read.
freopen
FILE *freopen(const char *filename, const char *mode, FILE *stream)
Returns NULL if error.
fscanf
int fscanf(FILE *stream, const char *format, ...)
Reads from 'stream' and assigns values through subsequent arguments which
must be pointers. Returns EOF if end of file occurs before any conversion;
otherwise it returns number of items assigned. Format string should contain
conversion specifications consisting of '%' followed by:
flag: * suppression; ignore field number: n first number specifies maximum field width width character: h short l long L long double conversion characters: d int * i int *; may be octal (leading 0) or hexadecimal (leading 0x) o int *; octal integer x int *; hexadecimal integer c char *; characters s char *; string of non-white characters e,f float *; could also use 'g' p void *; pointer n int *; writes into arg number of characters read. Nothing read.
fseek
int fseek(FILE *stream, long offset, int origin)
Sets file position. Values for origin can be:
SEEK_SET beginning
SEEK_CUR current position
SEEK_END end of file
fsetpos
int fsetpos(FILE *stream, const fpos_t *ptr)
Positions 'stream' at position recorded by fgetpos. Returns non-zero if
error.
ftell
long ftell(FILE *stream)
Returns current position for 'stream', or -1L if error.
fwrite
size_t fwrite(const void *ptr, size_t size, size_t nobj, FILE *stream)
Writes from 'ptr' to 'stream' 'nobj' objects of size 'size'. Returns number
of objects read.
getc
int getc(FILE *stream)
Same as fgetc, except a macro.
getchar
int getchar(void)
Equivalent to getc(stdin).
gets
char *gets(char *s)
Returns s, or NULL if error.
perror
void perror(const char *s)
Prints error message 's'.
printf
int printf(const char *format, ...)
Equivalent to fprintf(stdout, ...)
putc
int putc(int c, FILE *stream)
Same as fputc, except a macro.
putchar
int putchar(int c)
Equivalent to putc(c, stdout).
puts
int puts(const char *s)
Returns non-negative result, or EOF if error.
remove
int remove(cost char *filename)
Returns non-zero if attempt to delete file fails.
rename
int rename(const char *oldname, const char *newname)
Returns non-zero if attempt to rename file fails.
rewind
void rewind(FILE *stream)
scanf
int scanf(const char *format, ...)
Identical to fscanf(stdin, ...)
sprintf
int sprintf(char *s, const char *format, ...)
Same as printf except output written to string 's'.
sscanf
int sscanf(char *s, const char *format, ...)
Equivalent to scanf(...) except input is taken from 's'.
setbuf
void setbuf(FILE *stream, char *buf)
If 'buf' is NULL, buffering is turned off, otherwise equivalent to 'void
setvbuf(stream, buf, _IOFBF, BUFSIZE)'.
setvbuf
int setvbuf(FILE *stream, char *buf, int mode, size_t size)
Returns non-zero if error. A value of NULL for 'buf' allocates buffer.
modes:
_IOFBF full buffering
_IOLBF line buffering
_IONBF no buffering
tmpfile
FILE *tmpfile(void)
Returns NULL if error.
tmpnam
char *tmpnam(char s[L_tmpnam])
tmpnam(NULL) creates unique filename. TMP_MAX different names guaranteed.
ungetc
int ungetc(int c, FILE *stream)
Pushes 'c' (converted to an unsigned char) back onto 'stream'. Returns 'c'
or EOF if error.
vprintf
int vprintf(const char *format, va_list arg)
vfprintf
int vfprintf(FILE *stream, const char *format, va_list arg)
vsprintf
int vsprintf(char *s, const char *format, va_list arg)
abort
void abort(void)
Causes program to abnormally terminate.
abs
int abs(int n)
atexit
int atexit(void (*fcn)(void))
Registers function to be called when program terminates. Returns non-zero
if error.
atof
double atof(const char *s)
atoi
int atoi(const char *s)
atol
long atol(const char *s)
bsearch
void *bsearch(const void *key, const void *base, size_t n, size_t size,
int (*cmp)(const void *keyval, const void *datum))
calloc
void *calloc(size_t nobj, size_t size)
div
div_t div(int num, int denom)
exit
void exit(int status)
Causes normal program termination.
free
void free(void *p)
Deallocates spaced pointed to by 'p'. Returns NULL if error.
getenv
char *getenv(const char *name)
labs
long labs(long n)
ldiv
ldiv_t ldiv(long num, long denom)
malloc
void *malloc(size_t size)
Returns pointer for object of size 'size', or NULL if request for memory
denied.
mblen
int mblen(const char *s, size_t n)
Multi-byte function. Returns number of bytes of character s.
mbstowcs
size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n)
Multi-byte function. Copies elements of s to pcws, stopping after it copies
n elements or a NULL character. Returns number of characters copied.
mbtowc
int mbtowc(wchar_t *pwc, const char *s, size_t n)
Multi-byte function. Sets pwc to the first element of s if s is not NULL
and n is not zero. Returns 1 if successful, zero if s is NULL, and -1 if
n is zero.
qsort
void qsort(void *base, size_t n, size_t size, int (*cmp)(const void *, const
void *))
rand
int rand(void)
Returns pseudo-random integer between 0 and RAND_MAX.
realloc
void *realloc(void *p, size_t size)
strtod
double strtod(const char *s, char **endp)
strtol
long strtol(const char *s, char **endp, int base)
strtoul
unsigned long strtoul(const char *s, char **endp, int base)
srand
void srand(unsigned int seed)
system
int system(const char *s)
If system provides a command processor, executes command line in s. If s
is NULL and there is a command processor, returns non-zero value, otherwise
returns zero.
wcstombs
size_t wcstombs(wchar_t *pwcs, const char *s, size_t n)
Multi-byte function. Copies elements of pwcs to s, stopping after it copies
n elements or the NULL character. Returns the number of characters copied.
wctomb
int wctomb(char *s, wchar_t wchar)
Multi-byte function. Sets first element of s to wchar if s is not NULL.
memchr
void *memchr(const char *cs, int c, size_t n)
Returns first occurrence of character 'c' in 'cs' or NULL.
memcmp
int memcmp(const char *cs, const char *ct, size_t n)
Compares 'n' characters of 'cs' with 'ct'.
memcpy
void *memcpy(char *s, const char *ct, size_t n)
Copy 'n' characters from 'ct' to 's', returns 's'.
memmove
void *memmove(char *s, const char *ct, size_t n)
Same as 'memcpy'. Works if objects overlap.
memset
void *memset(char *s, int c, size_t n)
Put character 'c' into first 'n' characters of 's', returns 's'.
strcat
char *strcat(char *char *s, const char *ct)
Concatenates 'ct' to 's', returns 's'.
strchr
char *strchr(const char *cs, int c)
Returns pointer to first occurrence of 'c' in 'cs' or NULL.
strcmp
int strcmp(const char *cs, const char *ct)
Returns zero if cs == ct.
strcoll
int strcoll(const char *cs, const char *ct)
Compare strings based on locale environment. Equivalent to strcmp.
strcpy
char *strcpy(char *s, const char *ct)
Copies 'ct' to 's', including '\0', returns 's'.
strcspn
size_t strcspn(const char *cs, const char *ct)
strerror
char *strerror(n)
Returns pointer to string defining error 'n'.
strlen
size_t strlen(const char *cs)
Returns length of 'cs'.
strncat
char *strncat(char *s, const char *ct, size_t n)
strncmp
int strncmp(const char *cs, const char *ct, size_t n)
Returns zero if 'n' characters of both strings are equal.
strncpy
char *strncpy(char *s, const char *ct, size_t n)
strpbrk
char *strpbrk(const char *cs, const char *ct)
Return pointer to first occurrence of any character in 'ct' or NULL.
strrchr
char *strrchr(const char *cs, int c)
Returns pointer to last occurrence of 'c' in 'cs' or NULL.
strspn
size_t strspn(const char *cs, const char *ct)
strstr
char *strstr(const char *cs, const char *ct)
Returns pointer to first occurrence of string 'ct' in 'cs' or NULL.
strtok
char *strtok(char *s, const char *ct)
Searches 's' for tokens delimited by characters from 'ct'. Returns NULL
when no further tokens found.
strxfrm
size_t strxfrm(char *cs, const char *ct, size_t n)
Copies the first n characters of ct into cs. If n is zero, cs can be NULL.
Equivalent to strncpy except strxfrm returns length of ct.
In the following list, 'x' and 'y' are type 'double', n is type 'int'. All angles for trigonometric functions are in radians.
sin(x)
cos(x)
tan(x)
asin(x)
acos(x)
atan(x)
atan2(y,x)
sinh(x)
cosh(x)
tanh(x)
exp(x)
log(x)
log10(x)
pow(x,y)
sqrt(x)
ceil(x)
floor(x)
fabs(x)
ldexp(x,n)
frexp(x, int *exp)
modf(x, double *ip)
fmod(x,y)
All functions in <ctype.h> take a character and return an 'int' which represents a true (non-zero) or false (zero) result.
isalnum(int c) alpha-numeric character
isalpha(int c) upper or lower-case letter
iscntrl(int c) control character
isdigit(int c) decimal digit
isgraph(int c) !space
islower(int c) lower-case
isprint(int c) printing character, including space
ispunct(int c) !(space || letter || digit)
isspace(int c) space, tab, newline
isupper(int c) upper-case
isxdigit(int c) hexadecimal digit
tolower(int c) converts and returns lowercase letter
toupper(int c) converts and returns uppercase letter
Many functions in <time.h> utilize a data structure which has the following format:
struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; // Daylight Savings Time flag };
asctime
char *asctime(const struct tm *tp)
Converst time into standard string; "Fri May 26 19:27:30 1995\n".
clock
clock_t clock(void)
Returns processor time used by the program.
ctime
char *ctime(const time_t *tp)
Converts calendar time to local time.
difftime
double difftime(time_t time2, time_t time1)
Returns difference in two times in seconds.
gmtime
struct tm *gmtime(const time_t *tp)
Converts calendar time into Coordinated Universal Time (UTC).
localtime
struct tm *localtime(const time_t *tp)
Converts calendar time into local time.
mktime
time_t mktime(struct tm *tp)
Converts local time to calendar time.
strftime
size_t strftime(char *s,size_t smax,const char *fmt,const struct tm *tp)
Formats date and time data from *tp into string 's'. Available formats include:
%a abbriviated weekday name %A full weekday %b abbreviated month %B full month %c date and time %d day of month (01-31) %H hour (24 hr) %I hour (12 hr) %j day of year %m month %M minute %p AM or PM %S second %U week number (Sunday 1st day of week) %w weekday (0-6) %W week number (Monday 1st day of week) %x date %X time %y year without century %Y century %Z time zone name %% %
time
time_t time(time_t *tp)
Returns current calendar time. If 'tp' is not NULL, return value is also
assigned to 'tp'.
Use the functions in <stdarg.h> to retrieve arguments from a variable length function argument list. An example of using variable argument lists can be found in Section 'Functions'. Before using functions, you must declare a variable of type 'va_list' as follows:
va_list ap;
You then use the 'va_start' macro to initialize. Afterwords, each subsequent call to 'va_arg' returns the next argument. Finally, call 'va_end'.
va_start
void va_start(va_list ap, lastarg)
Provide the last argument in a variable length function list as 'lastarg'
to initialize va_list variable.
va_arg
type va_arg(va_list ap, type)
Returns next argument in variable length function list. You must supply
the data type in 'type'. va_arg returns type specified in 'type'.
va_end
void va_end(va_list ap)
Execute after arguments have been processed, but prior to exiting function.
The following constants are defined in <limits.h>:
CHAR_BIT CHAR_MAX CHAR_MIN INT_MAX INT_MIN LONG_MAX LONG_MIN SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
The following constants are defined in <float.h>:
FLT_RADIX FLT_ROUNDS FLT_DIG FLT_EPSILON FLT_MANT_DIG FLT_MAX FLT_MAX_EXP FLT_MIN FLT_MIN_EXP DBL_DIG DBL_EPSILON DBL_MANT_DIG DBL_MAX DBL_MAX_EXP DBL_MIN DBL_MIN_EXP
assert
void assert(int expr)
If 'expr' is zero, prints error message on stderr. If NDEBUG is defined,
assert macro is ignored.
setjmp
int setjmp(jmp_buf env)
Saves state information for later use by 'longjmp'.
longjmp
void longjmp( jmp_buf env, int val)
Restores state saved by most recent call to setjmp. Execution resumes as
if the setjmp function had just executed and returned the non-zero value
val. Function containing setjmp must not have terminated.
signal
void (*signal(int sig, void (*handler)(int)))(int)
Calls function pointed to by handler with argument of the type of signal.
SIG_DFL default behavior: handler ignored
SIG_IGN ignore signal: handler ignored
SIGABRT abnormal termination
SIGFPE arithmetic error
SIGILL illegal instruction
SIGINT interrupt
SIGSEGV illegal storage access
SIGTERM termination request
raise
int raise( int sig )
Sends the signal 'sig' to the program, returns non-zero if unsuccessful.
localeconv
struct lconv *localeconv(void)
Returns structure of formatting requirements according to the rules of the
current locale.
setlocale
char *setlocale(int category, const char *locale)
Sets locale environment. The parameter category can be one of the following:
LC_ALL LC_COLLATE LC_TYPE LC_MONETARY LC_NUMERIC LC_TIME
fstat
int fstat(int fn, struct stat *statptr)
Returns file information into statptr data structure. Returns zero if successful.
putw
int putw(int word, FILE *stream)
Writes word to stream. Returns word is successful, EOF if not.
stat
int stat(char *filename, struct stat *statptr)
Returns file information about filename into statptr data structure. Returns
zero if successful.
[ Prev | Table of Contents | Next ]