The Standard C Library

This page contains a brief summary of some useful functions found in the standard C Library. The functions are organized according to the header file in which they are found. This list is not exhaustive, nor is it meant to fully describe each function. For greater understanding of any of these functions, consult the man pages for that function. Looking at the header files themselves (found in /usr/include) can also be very informative.


Only one function here, void assert(int ). If the value in the argument is non-zero, nothing exciting happens. The program continues on. If the argument evaluates to zero, the program dies after printing a message on the standard error file (usually the screen).

The ONLY reasonable use for this function is in debugging. You sprinkle assert()s throughout the program, giving as the argument an expression that you think should be true at that point in the program. When the program runs, it evaluates your assertion (expression). If you were wrong, the program tells you where it's at, dies, and you get to figure out why your logic was wrong at that point. A very useful function.

But wait, there's more! If you #define NDEBUG before #include <assert.h> all of your assert()s are cheerfully ignored. So you can enable or disable all of your debugging checking by changing a single line.


This file declares functions useful for testing if characters fall in certain common categories. All of these functions take an unsigned character value or EOF (OK OK, they really take an int) and return a non-zero or zero value according to whether the character meets or does not meet the given criterion. These functions are usually implemented as lookup tables optimized for each specific architecture, so calling isupper(c) is much faster than if(c >= 'A' && c <='Z') ... .
a letter or numeric digit
a letter
a control character
a decimal digit
a printable character but not white space
a lower-case letter
a printable character, including white space
anything printable except letters, numbers, or white space (almost everything!)
white space, i.e. space, tab, line feed, carriage return, form feed, vertical tab.
an upper-case letter
a hexadecimal digit
The following two functions convert characters to lower and upper case respectively when possible. If the character can't be converted, it is returned as is.
int tolower(int c)
converts c to lower case
int toupper(int c)
converts c to upper case


This file specifies the minimum and maximum values for various integer types. The values are specific to the machine architecture, including the operating system. In other words, if you go to a machine like this one, the limits should be the same. If you go to a different machine, they might be the same. For example, the maximum value of an unsigned int is 65535 on a PC running DOS, and 4294967295 on a PC running Unix. The maxmimum value of an unsigned long int is 4294967295 on a Pentium class machine running Unix and 18446744073709551615 on a DEC Alpha machine running Unix.

Many programs break down when ported to different architectures because they make assumptions about the capacity of fundamental types. Using this header file helps eliminate that problem.

These values are all #defined in <limits.h>

limits for signed characters.
limit for unsigned characters.
limits for characters.
limits for signed short integers.
limit for unsigned short integers.
limits for integers.
limit for unsigned integers.
limits for (signed) long integers.
limit for unsigned integers.


This file is the same as <limits.h> except for floating point types instead of integers. These #defined values can vary according to architecture. Very important for portability of numeric processing programs.
limits for floats.
limits for doubles.
the smallest number x such that 1+x is different from 1. This is important in scientific calculations and helps determine how much accuracy you can expect out of your numeric algorithms.



This file contains numerous functions, including conversions from strings to numbers, random number generation, dynamic memory manipulation, and sorting. It's a hodgepodge of useful routines that don't fit well in other files.
double atof(char *), int atoi(char *), and long atol(char *)
convert a numeric string into a double, an integer and a long integer respectively. These functions are very useful for converting numeric values from command line arguments.
double strtod(), long strtol(), and strtoul()
more robust versions of atof() and friends. The integer versions are able to convert numbers of different bases. Each of the str... functions also returns a pointer to the location in the string where it stopped the conversion.
int rand(void)
returns a pseudo-random integer in the range of 0 to RAND_MAX which is a symbolic constant also defined in this file.
void srand(unsigned int)
resets the random number generator using the integer passed in as a "seed". Using the same seed lets a program use the same sequence of random numbers, which gives a program reproducible behavior. Important for many simulations. Changing the seed also forces a new random number sequence, also useful for simulations.
void * malloc(int)
dynamically allocates the number of bytes indicated from system memory and returns a pointer to this new memory. The memory is uninitialized. If for some reason, the memory can not be allocated, malloc() returns NULL.
void * calloc(int n_obj, int size)
dynamically allocates memory to hold n_obj objects, each containing size bytes. Also initializes the allocated memory to all zeros. Much faster than using malloc() and then writing your own loop to clear the memory. If you have to initialize the memory to some complex value, calloc() is a waste of time.
void * realloc(void * p, int size)