The ANSI C library classifies functions into several groups, with each group having an associated header file. This appendix gives you an overview of the library, listing the header files and briefly describing their associated functions. Some of these functions (for example, several I/O functions) are discussed in much greater detail in the text. More generally, for complete descriptions, consult the documentation for your implementation, or a reference manual
Input and Output
Input and Output contains sections on I/O streams, sequential and random file access , formatted I/O, and error handling.
General file access functions
|
Purpose |
Functions in stdio.h |
Functions in wchar.h |
---|---|---|
Get/set stream orientation |
fwide( ) |
|
Write characters |
fputc( ), putc( ), putchar( ) |
fputwc( ), putwc( ), putwchar( ) |
Read characters |
fgetc( ), getc( ), getchar( ) |
fgetwc( ), getwc( ), getwchar( ) |
Put back characters read |
ungetc( ) |
ungetwc( ) |
Write lines |
fputs( ), puts( ) |
fputws( ) |
Read lines |
fgets( ), gets( ) |
fgetws( ) |
Write blocks |
fwrite( ) |
|
Read blocks |
fread( ) |
|
Write formatted strings |
printf( ), vprintf( ) fprintf( ), vfprintf( ) sprintf( ), vsprintf( ) snprintf( ), vsnprintf() |
wprintf( ), vwprintf( ) fwprintf( ), vfwprintf( ) swprintf( ), vswprintf( ) |
Read formatted strings |
scanf( ), vscanf( ) fscanf( ), vfscanf( ) sscanf( ), vsscanf( ) |
wscanf( ), vwscanf( ) fwscanf( ), vfwscanf( ) swscanf( ), vswscanf( ) |
Purpose |
Functions declared in stdlib.h |
Functions declared in stdint.h |
---|---|---|
Absolute value |
abs( ), labs( ), llabs( ) |
imaxabs( ) |
Division |
div( ), ldiv( ), lldiv( ) |
imaxdiv( ) |
Random numbers |
rand( ), srand( ) |
Mathematical function |
C functions in math.h |
C functions in complex.h |
---|---|---|
Trigonometry |
sin( ), cos( ), tan( ) asin( ), acos( ), atan( ) |
csin( ), ccos( ), ctan( ) casin( ), cacos( ), catan( ) |
Hyperbolic trigonometry |
sinh( ), cosh( ), tanh( ) asinh( ), acosh( ), atanh( ) |
csinh( ), ccosh( ), ctanh( ) casinh( ), cacosh( ), catanh( ) |
Exponential function |
exp( ) |
cexp( ) |
Natural logarithm |
log( ) |
clog( ) |
Powers, square root |
pow( ), sqrt( ) |
cpow( ), csqrt( ) |
Absolute value |
fabs( ) |
cabs( ) |
Mathematical function |
C function |
---|---|
Arctangent of a quotient |
atan2( ) |
Exponential functions |
exp2( ), expm1( ), frexp( ), ldexp( ) scalbn( ), scalbln( ) |
Logarithmic functions |
log10( ), log2( ), log1p( ), logb( ), ilogb( ) |
Roots |
cbrt( ), hypot( ) |
Error functions for normal distributions |
erf( ), erfc( ) |
Gamma function |
tgamma( ), lgamma( ) |
Remainder |
fmod( ), remainder( ), remquo( ) |
Separate integer and fractional parts |
modf( ) |
Next integer |
ceil( ), floor( ) |
Next representable number |
nextafter( ), nexttoward( ) |
Rounding functions |
trunc( ), round( ), lround( ), llround( ), nearbyint( ), rint( ), lrint( ), llrint( ) |
Positive difference |
fdim( ) |
Multiply and add |
fma( ) |
Minimum and maximum |
fmin( ), fmax( ) |
Assign one number's sign to another |
copysign( ) |
Generate a NaN |
nan( ) |
Mathematical function |
C function |
---|---|
Isolate real and imaginary parts |
creal( ), cimag( ) |
Argument (the angle in polar coordinates) |
carg( ) |
Conjugate |
conj( ) |
Project onto the Riemann sphere |
cproj( ) |
Category |
Functions in ctype.h |
Functions in wctype.h |
---|---|---|
Letters |
isalpha( ) |
iswalpha( ) |
Lowercase letters |
islower( ) |
iswlower( ) |
Uppercase letters |
isupper( ) |
iswupper( ) |
Decimal digits |
isdigit( ) |
iswdigit( ) |
Hexadecimal digits |
isxdigit( ) |
iswxdigit( ) |
Letters and decimal digits |
isalnum( ) |
iswalnum( ) |
Printable characters (including whitespace) |
isprint( ) |
iswprint( ) |
Printable, non-whitespace characters |
isgraph( ) |
iswgraph( ) |
Whitespace characters |
isspace( ) |
iswspace( ) |
Whitespace characters that separate words in a line of text |
isblank( ) |
iswblank( ) |
Punctuation marks |
ispunct( ) |
iswpunct( ) |
Control characters |
iscntrl( ) |
iswcntrl( ) |
Conversion |
Functions in ctype.h |
Functions in wctype.h |
---|---|---|
Upper- to lowercase |
tolower( ) |
towlower( ) |
Lower- to uppercase |
toupper( ) |
towupper( ) |
Purpose |
Functions in string.h |
Functions in wchar.h |
---|---|---|
Find the length of a string. |
strlen( ) |
wcslen( ) |
Copy a string. |
strcpy( ), strncpy( ) |
wcscpy( ), wcsncpy( ) |
Concatenate strings. |
strcat( ), strncat( ) |
wcscat( ), wcsncat( ) |
Compare strings. |
strcmp( ), strncmp( ), strcoll( ) |
wcscmp( ), wcsncmp( ), wcscoll( ) |
Transform a string so that a comparison of two transformed strings using strcmp( ) yields the same result as a comparison of the original strings using the locale-sensitive function strcoll( ). |
strxfrm( ) |
wcsxfrm( ) |
In a string, find: |
||
|
strchr( ), strrchr( ) |
wcschr( ), wcsrchr( ) |
|
strstr( ) |
wcsstr( ) |
|
strcspn( ), strpbrk( ) |
wcscspn( ), wcspbrk( ) |
|
strspn( ) |
wcsspn( ) |
Parse a string into tokens |
strtok( ) |
wcstok( ) |
Purpose |
Functions in stdlib.h |
Functions in wchar.h |
---|---|---|
Find the length of a multibyte character |
mblen( ) |
mbrlen( ) |
Find the wide character corresponding to a given multibyte character |
mbtowc( ) |
mbrtowc( ) |
Find the multibyte character corresponding to a given wide character |
wctomb( ) |
wcrtomb( ) |
Convert a multibyte string into a wide string |
mbstowcs( ) |
mbsrtowcs( ) |
Convert a wide string into a multibyte string |
wcstombs( ) |
wcsrtombs( ) |
Convert between byte characters and wide characters |
btowc( ), wctob( ) |
|
Test for the initial shift state |
mbsinit( ) |
Conversion |
Functions in stdlib.h |
Functions in wchar.h |
---|---|---|
String to int |
atoi( ) |
|
String to long |
atol( ), strtol( ) |
wcstol( ) |
String to unsigned long |
strtoul( ) |
wcstoul( ) |
String to long long |
atoll( ), strtoll( ) |
wcstoll( ) |
String to unsigned long long |
strtoull( ) |
wcstoull( ) |
String to float |
strtof( ) |
wcstof( ) |
String to double |
atof( ), strtod( ) |
wcstod( ) |
String to long double |
strtold( ) |
wcstold( ) |
Purpose |
Functions in string.h |
Functions in wchar.h |
---|---|---|
Copy a memory block, where source and destination do not overlap |
memcpy( ) |
wmemcpy( ) |
Copy a memory block, where source and destination may overlap |
memmove( ) |
wmemmove( ) |
Compare two memory blocks |
memcmp( ) |
wmemcmp( ) |
Find the first occurrence of a given character |
memchr( ) |
wmemchr( ) |
Fill the memory block with a given character value |
memset( ) |
wmemset( ) |
Purpose |
Function |
---|---|
Allocate a block of memory |
malloc( ) |
Allocate a memory block and fill it with null bytes |
calloc( ) |
Resize an allocated memory block |
realloc( ) |
Release a memory block |
free( ) |
Purpose |
Function |
---|---|
Get the amount of CPU time used |
clock( ) |
Get the current calendar time |
time( ) |
Convert calendar time to struct tm |
gmtime( ) |
Convert calendar time to struct tm with local time values |
localtime( ) |
Normalize the values of a struct tm object and return the calendar time with type time_t |
mktime( ) |
Convert calendar time to a string |
ctime( ), strftime( ), wcsftime( ) |