1assert.h
void assert(int expression);
Macro used for internal error detection. (Ignored if
href="http://baike.baidu.com/view/2819422.htm"
target=_blank>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__.
is control character. In ASCII, control characters are
0x00 (NUL) to 0x1F (US), and 0x7F (DEL)
is printing character other than space
is printing character (including space). In ASCII,
printing characters are 0x20 (' ') to 0x7E ('~')
is printing character other than space, letter,
is space, formfeed, newline, carriage return, tab,
object to which certain library functions assign
specific positive values on error
other implementation-defined error values are
to determine the value (if any) assigned to errno by a
library function, a program should assign zero to errno immediately
radix of floating-point representations
Where the prefix "FLT" pertains to type float, "DBL"
to type double, and "LDBL" to type long double:
smallest number x such that 1.0 + x != 1.0
number of digits, base FLT_RADIX, in mantissa
largest positive integer exponent to which FLT_RADIX
can be raised and remain representable
smallest negative integer exponent to which FLT_RADIX
can be raised and remain representable
maximum value of type signed char
minimum value of type signed char
maximum value of type unsigned char
maximum value of type unsigned short
maximum value of type unsigned int
maximum value of type unsigned long
Describes formatting of monetary and other numeric
decimal point for non-monetary values
sizes of digit groups for non-monetary values
separator for digit groups for non-monetary values
decimal point for monetary values
sizes of digit groups for monetary values
separator for digit groups for monetary values (left
negative sign for monetary values
positive sign for monetary values
number of digits to be displayed to right of "decimal
number of digits to be displayed to right of "decimal
point" for international monetary values
whether currency symbol precedes (1) or follows (0)
whether currency symbol is (1) or is not (0) separated
by space from negative monetary values
format for negative monetary values:
parentheses surround quantity and currency
sign precedes quantity and currency symbol
sign follows quantity and currency symbol
sign immediately precedes currency symbol
sign immediately follows currency symbol
whether currency symbol precedes (1) or follows (0)
whether currency symbol is (1) or is not (0) separated
by space from non-negative monetary values
format for non-negative monetary values, with values
Implementations may change field order and include
additional fields. Standard C Library functions use only
struct lconv*localeconv(void);
returns pointer to formatting information for current
char* setlocale(int category, const char*
Sets components of locale according to specified
category and locale. Returns string describing new locale or null
on error. (Implementations are permitted to define values of
category additional to those describe here.)
category argument for all categories
category for numeric formatting information
category for monetary formatting information
category for information affecting collating
category for information affecting character class
category for information affecting time conversions
On domain error, implementation-defined value returned
and errno set to EDOM. On range error, errno set to ERANGE and
return value is HUGE_VAL with correct sign for overflow, or zero
for underflow. Angles are in radians.
magnitude returned (with correct sign) on overflow
double pow(double x, double y);
smallest integer not less than x
largest integer not greater than x
doublefrexp(double x, int* exp);
if x non-zero, returns value, with absolute value in
interval [1/2, 1), and assigns to *exp integer such that product of
return value and 2 raised to the power *exp equals x; if x zero,
both return value and *exp are zero
double modf(double x, double* ip);
returns fractional part and assigns to *ip integral
part of x, both with same sign as x
double fmod(double x, double y);
if y non-zero, floating-point remainder of x/y, with
same sign as x; if y zero, result is implementation-defined
double atan2(double y, double x);
type of object holding context information
Saves context information in env and returns zero.
Subsequent call to longjmp with same env returns non-zero.
void longjmp(jmp_buf env, int val);
Restores context saved by most recent call to setjmp
with specified env. Execution resumes as a second return from
setjmp, with returned value val if specified value non-zero, or 1
(asynchronous) interactive attention
(asynchronous) termination request
specifies default signal handling
signal return value indicating error
specifies that signal should be ignored
Install handler for subsequent signal sig. If handler
is SIG_DFL, implementation-defined default behaviour will be used;
if SIG_IGN, signal will be ignored; otherwise function pointed to
by handler will be invoked with argument sig. In the last case,
handling is restored to default behaviour before handler is called.
If handler returns, execution resumes where signal occurred. signal
returns the previous handler or SIG_ERR on error. Initial state is
implementation-defined. Implementations may may define signals
additional to those listed here.
Sends signal sig. Returns zero on success.
type of object holding context information
void va_start(va_list ap, lastarg);
Initialisation macro which must be called once before
any unnamed argument is accessed. Stores context information in ap.
lastarg is the last named parameter of the function.
type va_arg(va_list ap, type);
Yields value of the type (type) and value of the next
Termination macro which must be called once after
argument processing and before exit from function.
Offset (in bytes) of member m from start of structure
Type for objects declared to store result of
Type for objects declared to store result of sizeof
Value used to indicate end-of-stream or to report an
Maximum length required for array of characters to
Maximum number of files which may be open
Number of characters required for temporary filename
Value for origin argument to fseek specifying current
Value for origin argument to fseek specifying end of
Value for origin argument to fseek specifying
Minimum number of unique filenames generated by calls
Value for mode argument to setvbuf specifying full
Value for mode argument to setvbuf specifying line
Value for mode argument to setvbuf specifying no
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
Type for objects declared to store file position
Type for objects declared to store result of sizeof
FILE* fopen(const char* filename, const char*
Opens file named filename and returns a stream, or
NULL on failure. mode may be one of the following for text
text update (reading and writing)
text update, discarding previous content (if
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,
Closes file associated with stream, then opens file
filename with specified mode and associates it with stream. Returns
Flushes stream stream and returns zero on success or
EOF on error. Effect undefined for input stream. fflush(NULL)
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
int rename(const char* oldname, const char*
Changes name of file oldname to newname. Returns
Creates temporary file (mode "wb+") which will be
removed when closed or on normal program termination. Returns
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
int setvbuf(FILE* stream, char* buf, int
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.
voidsetbuf(FILE* stream, char* buf);
Controls buffering for stream stream. For null buf,
turns off buffering, otherwise equivalent to (void)setvbuf(stream,
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
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
(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).
int argument, printed in signed decimal notation
int argument, printed in unsigned octal notation
int argument, printed in unsigned hexadecimal
int argument, printed in unsigned decimal
int argument, printed as single character
double argument, printed with format [-]mmm.ddd
double argument, printed with format
void* argument, printed as pointer
int* argument : the number of characters written to
this point is written into argument
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
int vfprintf(FILE* stream, const char* format, va_list
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
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
conversion specifications, consisting of:
(optional) assignment suppression character "*"
(optional) maximum field width
(optional) target width indicator:
argument is pointer to short rather than int
argument is pointer to long rather than int, or double
argument is pointer to long double rather than
decimal integer; int* parameter required
integer; int* parameter required; decimal, octal or
octal integer; int* parameter required
unsigned decimal integer; unsigned int* parameter
hexadecimal integer; int* parameter required
characters; char* parameter required;white-spaceis not skipped, and NUL-termination is not
string of non-white-space; char* parameter required; string is
floating-point number; float* parameter required
pointer value; void* parameter required
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
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.
Returns next character from (input) stream stream, or
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 on
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
Copies characters from stdin into s until newline
encountered, end-of-file reached, or error occurs. Does not copy
newline. NUL-terminates s. Returns s, or NULL on end-of-file or
error. Should not be used because of the potential for buffer
int putc(int c, FILE* stream);
Equivalent to fputc except that it may be a
putchar(c) is equivalent to putc(c, stdout).
Writes s (excluding terminating NUL) and a newline to
stdout. Returns non-negative on success, EOF on error.
intungetc(int c, FILE* stream);
Pushes c (which must not be EOF), onto (input) stream
stream such that it will be returned by the next read. Only one
character of pushback is guaranteed (for each stream). Returns c,
size_t fread(void* ptr, size_t size, size_t nobj,
Reads (at most) nobj objects of size size from stream
stream into ptr and returns number of objects read. (feof and
ferror can be used to check status.)
size_tfwrite(const void* ptr, size_t size, size_t
Writes to stream stream, nobj objects of size size
from array ptr. Returns number of objects written.
int fseek(FILE* stream, long offset, int
Sets file position for stream stream and clears
end-of-file indicator. For a binary stream, file position is set to
offset bytes from the position indicated by origin: beginning of
file for SEEK_SET, current position for SEEK_CUR, or end of file
for SEEK_END. Behaviour is similar for a text stream, but offset
must be zero or, for SEEK_SET only, a value returned by ftell.
Returns current file position for stream stream, or -1
Equivalent to fseek(stream, 0L, SEEK_SET);clearerr(stream).
intfgetpos(FILE* stream, fpos_t* ptr);
Stores current file position for stream stream in
*ptr. Returns non-zero on error.
intfsetpos(FILE* stream, const fpos_t* ptr);
Sets current position of stream stream to *ptr.
Clears end-of-file and error indicators for stream
Returns non-zero if end-of-file indicator is set for
Returns non-zero if error indicator is set for stream
Prints s (if non-null) and strerror(errno) to standard
fprintf(stderr, "%s: %s\n", (s != NULL ? s : ""),
Value for status argument to exit indicating
Value for status argument to exit indicating
Maximum value returned by rand().
Return type of div(). Structure having members:
Return type ofldiv(). Structure having members:
Type for objects declared to store result of sizeof
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.
Equivalent to (int)strtol(s, (char**)NULL, 10) except
that errno is not necessarily set on conversion error.
Equivalent to strtol(s, (char**)NULL, 10) except that
errno is not necessarily set on conversion error.
double strtod(const char* s, char** endp);
Converts initial characters (ignoring leading white
space) of s to type double. If endp non-null, stores pointer to
unconverted suffix in *endp. On overflow, sets errno to ERANGE and
returns HUGE_VAL with the appropriate sign; on underflow, sets
errno to ERANGE and returns zero; otherwise returns converted
long strtol(const char* s, char** endp, int
Converts initial characters (ignoring leading white
space) of s to type long. If endp non-nu ll, stores pointer to
unconverted suffix in *endp. If base between 2 and 36, that base
used for conversion; if zero, leading (after any sign) 0X or 0x
implies hexadecimal, leading 0 (after any sign) implies octal,
otherwise decimal assumed. Leading 0X or 0x permitted for base
hexadecimal. On overflow, sets errno to ERANGE and returns LONG_MAX
or LONG_MIN (as appropriate for sign); otherwise returns converted
unsigned long strtoul(const char* s, char** endp, int
As for strtol except result is unsigned long and value
void* calloc(size_tnobj, size_t size);
Returns pointer to zero-initialised newly-allocated
space for an array of nobj objects each of size size, or NULL on
Returns pointer to uninitialised newly-allocated space
for an object of size size, or NULL on error.
void* realloc(void* p,size_tsize);
Returns pointer to newly-allocated space for an object
of size size, initialised, to minimum of old and new sizes, to
existing contents of p (if non-null), or NULL on error. On success,
old object deallocated, otherwise unchanged.
If p non-null, deallocates space to which it
Terminates program abnormally, by calling
Terminates program normally. Functions installed using
atexit are called (in reverse order to that in which installed),
open files are flushed, open streams are closed and control is
returned to environment. status is returned to environment in
implementation-dependent manner. Zero or EXIT_SUCCESS indicates
successful termination and EXIT_FAILURE indicates unsuccessful
termination. Implementations may define other values.
int atexit(void (*fcm)(void));
Registers fcn to be called when program terminates
normally (or when main returns). Returns non-zero on failure.
If s is not NULL, passes s to environment for
execution, and returns status reported by command processor; if s
is NULL, non-zero returned if environment has a command
char* getenv(const char* name);
Returns string associated with name name from
implementation's environment, or NULL if no such string
void*bsearch(const void* key, const void* base,size_tn, size_t size, int (*cmp)(const void* keyval,
Searches ordered array base (of n objects each of size
size) for item matching key according to comparison function cmp.
cmp must return negative value if first argument is less than
second, zero if equal and positive if greater. Items of base are
assumed to be in ascending order (according to cmp). Returns a
pointer to an item matching key, or NULL if none found.
void qsort(void* base,size_tn, size_t size, int (*cmp)(const void*, const
Arranges into ascending order array base (of n objects
each of size size) according to comparison function cmp. cmp must
return negative value if first argument is less than second, zero
if equal and positive if greater.
Returns pseudo-random number in range 0 to
void srand(unsigned int seed);
Uses seed as seed for new sequence of pseudo-random
Type for objects declared to store result of sizeof
char* strcpy(char* s, const char* ct);
Copies ct to s including terminating NUL and returns
char* strncpy(char* s, const char* ct,size_tn);
Copies at most n characters of ct to s. Pads with NUL
characters if ct is of length less than n. Note that this may leave
s without NUL-termination. Return s.
char* strcat(char* s, const char* ct);
Concatenate ct to s and return s.
char* strncat(char* s, const char* ct,size_tn);
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
int strncmp(const char* cs, const char* ct,size_tn);
Compares at most (the first) n characters of cs and
ct, returning negative value if csct.
int strcoll(const char* cs, const char* ct);
Compares cs with ct according to locale, returning
char* strchr(const char* cs, int c);
Returns pointer to first occurrence of c in cs, or
char* strrchr(const char* cs, int c);
Returns pointer to last occurrence of c in cs, or NULL
size_t strspn(const char* cs, const char* ct);
Returns length of prefix of cs which consists of
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,
size_t strlen(const char* cs);
Returns pointer to implementation-defined message
string corresponding with error n.
char* strtok(char* s, const char* t);
Searches s for next token delimited by any character
from ct. Non-NULL s indicates the first call of a sequence. If a
token is found, it is NUL-terminated and returned, otherwise NULL
is returned. ct need not be identical for each call in a
size_t strxfrm(char* s, const char* ct,size_tn);
Stores in s no more than n characters (including
terminating NUL) of a string produced from ct according to a
locale-specific transformation. Returns length of entire
void* memcpy(void* s, const void* ct,size_tn);
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_tn);
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
Compares at most (the first) n characters of cs and
ct, returning negative value if csct.
void*memchr(const void* cs, int c,size_tn);
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_tn);
Replaces each of the first n characters of s by c and
The number of clock_t units per second.
An arithmetic type elapsed processor representing
An arithmetic type representing calendar time.
Represents the components of calendar time:
Daylight Saving Time flag : is positive if DST is in
effect, zero if not in effect, negative if information not
Implementations may change field order and include
Returns elapsed processor time used by program or -1
Returns current calendar time or -1 if not available.
If tp is non-NULL, return value is also assigned to *tp.
doubledifftime(time_t time2, time_t time1);
Returns the difference in seconds between time2 and
If necessary, adjusts fields of *tp to fall withing
normal ranges. Returns the corresponding calendar time, or -1 if it
char* asctime(const struct tm* tp);
Returns the given time as a string of the form:
char* ctime(const time_t* tp);
Returns string equivalent to calendar time tp
converted to local time. Equivalent to:
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
size_t strftime(char* s, size_t smax, const char* fmt,
Formats *tp into s according to fmt. Places no more
than smax characters into s, and returns number of characters
produced (excluding terminating NUL), or 0 if greater than smax.
Formatting conversions (%c) are:
local date and time representation
local equivalent of "AM" or "PM"
week number of year (Sunday as 1st day of week)
week number of year (Monday as 1st day of week)
Local time may differ from calendar time because of