From http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html
[Last modified : 2006-11-30]
<assert.h>
: Diagnostics<ctype.h>
: Character Class Tests<stddef.h>
: Definitions of General Use<stdio.h>
: Input and Output<stdlib.h>
: Utility functions<string.h>
: String functionsvoid
assert(int
expression);
Macro used for internal
error detection. (Ignored if NDEBUG
is defined where <assert.h>
is included.) If expression equals zero, message printed on stderr
and abort called to terminate execution. Source filename
and line number in message are from preprocessor macros __FILE__
and __LINE__
.
[Contents]
int
isalnum(int
c);
isalpha
(
c)
or isdigit
(
c)
int
isalpha(int
c);
isupper
(
c)
or islower
(
c)
int
iscntrl(int
c);
is control
character. In ASCII, control characters are 0x00
(NUL
) to 0x1F
(US
),
and 0x7F
(DEL
int
isdigit(int
c);
is decimal digit
int
isgraph(int
c);
is printing character other than space
int
islower(int
c);
is lower-case letter
int
isprint(int
c);
is
printing character (including space). In ASCII, printing characters are 0x20
('
'
) to 0x7E
('~'
)
int
ispunct(int
c);
is printing character other than space, letter, digit
int
isspace(int
c);
is space, formfeed, newline, carriage return, tab, vertical tab
int
isupper(int
c);
is upper-case letter
int
isxdigit(int
c);
is hexadecimal digit
int
tolower(int
c);
return lower-case equivalent
int
toupper(int
c);
return upper-case equivalent
[Contents]
NULL
Null pointer constant.
offsetof
(
stype,
m)
Offset (in bytes) of member m from start of structure type stype.
ptrdiff_t
Type for objects declared to store result of subtracting pointers.
size_t
Type for objects declared to store
result of sizeof
operator.
[Contents]
Size of buffer
used by setbuf
.
Value used to indicate end-of-stream or to report an error.
FILENAME_MAX
Maximum length required for array of characters to hold a filename.
FOPEN_MAX
Maximum number of files which may be open simultaneously.
Number of characters required for
temporary filename generated by tmpnam
.
Null pointer constant.
Value for origin argument
to fseek
specifying current file position.
Value for origin argument
to fseek
specifying end of file.
Value for origin argument
to fseek
specifying beginning of file.
Minimum number of
unique filenames generated by calls to tmpnam
.
Value for mode argument
to setvbuf
specifying full buffering.
Value for mode argument
to setvbuf
specifying line buffering.
Value for mode argument
to setvbuf
specifying no buffering.
File pointer for standard input stream. Automatically opened when program execution begins.
File pointer for standard output stream. Automatically opened when program execution begins.
File pointer for standard error stream. Automatically opened when program execution begins.
Type of object holding information necessary to control a stream.
Type for objects declared to store file position information.
Type for objects declared to store
result of sizeof
operator.
FILE* fopen(const char*
filename, const char*
mode);
Opens file
named filename
and returns a stream, or NULL
on failure. mode may
be one of the following for text files:
"r"
text
reading
"w"
text
writing
"a"
text
append
"r+" text update
(reading and writing)
"w+"
text update, discarding
previous content (if any)
"a+"
text
append, reading, and writing at end
or one of
those strings with b
included (after the first character), for binary files.
FILE* freopen(const char*
filename, const
char*
mode, FILE*
stream);
Closes file associated with stream, then
opens file filename
with specified mode and associates it with stream. Returns stream or NULL
on error.
int
fflush(FILE*
stream);
Flushes stream stream
and returns zero on success or EOF on error. Effect
undefined for input stream. fflush(NULL)
flushes all output streams.
int
fclose(FILE*
stream);
Closes stream stream (after flushing, if output stream).
Returns EOF
on error, zero otherwise.
int
remove(const char*
filename);
Removes specified file. Returns non-zero on failure.
int
rename(const char*
oldname, const char*
newname);
Changes name of file oldname to newname. Returns non-zero on failure.
FILE* tmpfile();
Creates temporary file (mode "wb+"
)
which will be removed when closed or on normal program termination. Returns
stream or NULL
on failure.
char
* tmpnam(char
s[L_tmpnam]);
Assigns to s (if s non-null) and
returns unique name for a temporary file. Unique name is returned for each of
the first TMP_MAX
invocations.
int
setvbuf(FILE*
stream, char*
buf, int
mode, size_t
size);
Controls buffering for stream stream.
mode
is _IOFBF
for full buffering, _IOLBF
for line buffering, _IONBF
for no buffering. Non-null buf specifies buffer of size size
to be used; otherwise, a buffer is allocated. Returns
non-zero on error. Call must be before any other operation on stream.
void
setbuf(FILE*
stream, char*
buf);
Controls buffering for stream stream. For null buf,
turns off buffering, otherwise equivalent to (void)setvbuf(
stream,
buf, _IOFBF, BUFSIZ)
.
int
fprintf(FILE*
stream, const char*
format, ...);
Converts (according to format format) and writes output to stream stream. Number of characters written, or negative value on error, is returned. Conversion specifications consist of:
·
%
· (optional) flag:
-
left
adjust
+
always
sign
space space if no sign
0
zero pad
#
Alternate
form:
for conversion character o
, first digit will be zero, for [xX
],
prefix 0x
or 0X
to non-zero value, for
[eEfgG
],
always decimal point, for [gG
] trailing zeros not removed.
·
(optional) minimum
width: if specified as *
,
value taken from next argument (which must be int
).
·
(optional) .
(separating width from precision):
·
(optional) precision:
for conversion character s
,
maximum characters to be printed from the string, for [eEf
], digits after decimal point,
for [gG
],
significant digits, for an integer, minimum number of digits to be printed. If
specified as *
, value taken
from next argument (which must be int
).
· (optional) length modifier:
h
short
or unsigned short
l
long
or unsigned long
L long double
· conversion character:
d,
i
int
argument, printed in signed decimal notation
o
int
argument, printed in unsigned octal notation
x,
X
int
argument, printed in unsigned hexadecimal notation
u
int
argument, printed in unsigned decimal notation
c
int
argument, printed as single character
s
char*
argument
f
double
argument, printed with format [-
]mmm.
ddd
e,
E
double
argument,
printed with format [-
]m.
dddddd(e
|E
)(+
|-
)xx
g,
G
double
argument
p
void*
argument,
printed as pointer
n
int*
argument : the number of characters written to this point is
written into argument. This is an output specification!
%
no argument; prints %
int
printf(const char*
format, ...);
printf(f,
...)
is equivalent to fprintf(stdout, f, ...)
int
sprintf(char*
s, const char*
format, ...);
Like fprintf, but output written into string s, which must
be large enough to hold the output, rather than to a stream. Output is
NUL
-terminated. Returns length (excluding the terminating NUL
).
int
vfprintf(FILE*
stream, const char*
format, va_list
arg);
Equivalent to fprintf
with variable argument list replaced by arg,
which must have been initialised by the va_start
macro (and may have been used in calls to va_arg
).
int
vprintf(const char*
format, va_list
arg);
Equivalent to printf
with variable argument list replaced by arg,
which must have been initialised by the va_start
macro (and may have been used in calls to va_arg
).
int
vsprintf(char*
s, const
char*
format, va_list
arg);
Equivalent to sprintf
with variable argument list replaced by arg,
which must have been initialised by the va_start
macro (and may have been used in calls to va_arg
).
int
fscanf(FILE*
stream, const char*
format, ...);
Performs formatted input conversion, reading from stream stream
according to format format. The function
returns when format
is fully processed. Returns number of items converted and assigned, or EOF
if end-of-file or
error occurs before any conversion. Each of the arguments following format must be a pointer.
Format string may contain:
· blanks and tabs, which are ignored
· ordinary characters, which are expected to match next non-white-space of input
· conversion specifications, consisting of:
o
%
o
(optional) assignment suppression character
"*
"
o (optional) maximum field width
o (optional) target width indicator:
h
argument is
pointer to short
rather than
int
l
argument
is pointer to long
rather
than int
,
or double
rather
than float
L
argument is pointer to long double
rather than float
o conversion character:
d
decimal
integer; int
*
parameter required
i
integer;
int
*
parameter required; decimal, octal or
hex
o
octal integer; int
*
parameter required
u
unsigned
decimal integer; unsigned int*
parameter required
x
hexadecimal
integer; int
*
parameter required
c
characters;
char*
parameter required;
white-space is not skipped,
and NUL
-termination
is not performed
s
string
of non-white-space; char*
parameter required; string is
NUL
-terminated
e,
f,g
floating-point
number; float*
parameter
required
p
pointer value; void*
parameter required
n
chars read so
far; int
*
parameter required
[
...]
longest non-empty string from
specified set; char*
parameter
required; string is NUL
-terminated
[^
...]
longest non-empty string not
from specified set; char*
parameter
required; string is NUL
-terminated
%
literal %
; no assignment
int
scanf(const char*
format, ...);
scanf(f,
...)
is equivalent to fscanf(stdin, f, ...)
int
sscanf(char*
s, const
char*
format, ...);
Like fscanf
,
but input read from string s.
int
fgetc(FILE*
stream);
Returns next
character from (input) stream stream, or EOF
on end-of-file or
error.
char
* fgets(char*
s, int
n, FILE*
stream);
Copies characters from (input)
stream stream
to s,
stopping when n-1
characters copied, newline copied, end-of-file reached
or error occurs. If no error, s is NUL
-terminated.
Returns NULL
on end-of-file or error, s
otherwise.
int
fputc
(int
c, FILE*
stream);
Writes c, to stream stream.
Returns c,
or EOF
char* fputs(const char* s, FILE* stream);
Writes s, to (output) stream stream. Returns non-negative on success or EOF
on error.
Equivalent to
fgetc
except that
it may be a macro.
int putc(int c, FILE* stream);
Equivalent to
fputc
except that
it may be a macro.
putchar(c) is equivalent to putc(c, stdout).
int ungetc(int c, FILE* stream);
size_t
fread(void* ptr, size_t size, size_t nobj, FILE* stream);
size_t fwrite(const void*
ptr, size_t size, size_t nobj, FILE* stream);
int fseek(FILE* stream, long offset, int origin);
Returns
current file position for stream stream, or -1
on error.
Equivalent to
fseek(
stream, 0L, SEEK_SET); clearerr(
stream)
.
int fgetpos(FILE* stream, fpos_t* ptr);
Stores
current file position for stream stream in *
ptr. Returns non-zero on error.
int fsetpos(FILE* stream, const fpos_t* ptr);
Sets current position of stream stream
to *
ptr. Returns non-zero on error.
Clears end-of-file and error indicators for stream stream.
Returns non-zero if end-of-file indicator is set for stream stream.
Returns non-zero if error indicator is set for stream stream.
Prints s (if non-null) and strerror(errno)
to standard
error as would:
fprintf(stderr, "%s: %s\n", (s != NULL ? s : ""), strerror(errno))
Value for status argument to exit
indicating failure.
Value for status argument to exit
indicating success.
Maximum value
returned by rand()
.
Return type
of div()
. Structure
having members:
Return type
of ldiv()
. Structure
having members:
Type for
objects declared to store result of sizeof
operator.
div_t
div(int num, int denom);
ldiv_t ldiv(long num, long denom);
Returns quotient and remainder of num/
denom.
Equivalent to
strtod(
s, (char**)NULL)
except that errno
is not
necessarily set on conversion error.
double strtod(const char* s, char** endp);
long strtol(const char* s, char** endp, int base);
unsigned long strtoul(const char* s, char** endp, int base);
As for strtol
except
result is unsigned long
and value on
overflow is ULONG_MAX
.
void* calloc(size_t nobj, size_t size);
Returns pointer to uninitialised
newly-allocated space for an object of size size,
or NULL
on error.
void* realloc(void*
p, size_t size);
If p non-null, deallocates space to which it points.
Terminates
program abnormally, by calling raise(SIGABRT)
.
int atexit(void (*fcm)(void));
char* getenv(const
char* name);
void qsort(void*
base, size_t n, size_t size, int (*cmp)(const
void*, const void*));
Returns pseudo-random number in range 0
to RAND_MAX
.
void srand(unsigned
int seed);
Uses seed as seed for new sequence of
pseudo-random numbers. Initial seed is 1
.
Type for
objects declared to store result of sizeof
operator.
char* strcpy(char*
s, const char* ct);
Copies ct to s including terminating NUL
and returns s.
char* strncpy(char*
s, const char* ct, size_t n);
char* strcat(char* s, const char*
ct);
Concatenate ct to s and return s.
char* strncat(char* s, const char*
ct, size_t n);
Concatenate
at most n characters
of ct to s. NUL
-terminates s and return it.
int strcmp(const char* cs, const char* ct);
Compares cs with ct, returning negative value if cs<
ct, zero if cs==
ct, positive
value if cs>
ct.
int strncmp(const char* cs, const char* ct, size_t n);
int strcoll(const char* cs, const char* ct);
char* strchr(const char* cs, int c);
Returns
pointer to first occurrence of c in cs, or NULL
if not found.
char* strrchr(const
char* cs, int c);
Returns
pointer to last occurrence of c in cs, or NULL
if not found.
size_t
strspn(const char* cs, const char* ct);
Returns length of prefix of cs which consists of characters which are in ct.
size_t
strcspn(const char* cs, const char* ct);
Returns length of prefix of cs which consists of characters which are not in ct.
char* strpbrk(const char* cs, const char* ct);
Returns pointer to first occurrence in cs of any character of ct, or NULL
if none is found.
char* strstr(const
char* cs, const char*
ct);
Returns pointer to first occurrence of ct within cs, or NULL
if none is found.
size_t
strlen(const char* cs);
Returns pointer to implementation-defined message string corresponding with error n.
char* strtok(char* s, const char*
t);
size_t
strxfrm(char* s, const char*
ct, size_t n);
void* memcpy(void* s, const void* ct, size_t n);
Copies n characters from ct to s and returns s. s may be corrupted if objects overlap.
void* memmove(void* s, const void*
ct, size_t n);
Copies n characters from ct to s and returns s. s will not be corrupted if objects overlap.
int memcmp(const void* cs, const void* ct, size_t n);
void* memchr(const void* cs, int c, size_t n);
Returns
pointer to first occurrence of c in first n characters of cs, or NULL
if not found.
void* memset(void*
s, int c, size_t n);
Replaces each of the first n characters of s by c and returns s.
The number of
clock_t
units per
second.
An arithmetic type elapsed processor representing time.
An arithmetic (integer) type representing calendar time.
Represents the components of calendar time:
int tm_sec; seconds after the minute
int tm_min; minutes after the hour
int tm_hour; hours since midnight
int tm_mon; months since January
int tm_wday; days since Sunday
int tm_yday; days since January 1
int tm_isdst; Daylight Saving Time flag : is positive if DST is in effect,
zero if not in effect, negative if information not known.
Implementations may change field order and include
Returns
elapsed processor time used by program or -1
if not
available.
double difftime(time_t time2, time_t time1);
Returns the difference in seconds between time2 and time1.
char* asctime(const
struct tm* tp);
Returns the
given time as a string of the form:
Sun Jan 3 13:08:42 1988\n\0
char* ctime(const time_t* tp);
struct tm* gmtime(const
time_t* tp);
Returns
calendar time *
tp converted to Coordinated Universal
Time, or NULL
if not available.
struct tm* localtime(const time_t* tp);
Returns
calendar time *
tp converted into local time.
size_t strftime(char*
s, size_t smax, const char*
fmt, const struct tm* tp);
c local date and time representation
H hour (24-hour clock) [00-23]
I hour (12-hour clock) [01-12]
p local equivalent of "AM" or "PM"
U week number of year (Sunday as 1st day of week) [00-53]
W week number of year (Monday as 1st day of week) [00-53]
y year without century [00-99]
% % (i.e., %% inserts a literal % character).
Local time may differ from calendar time because of time zone.