Previous: 8 Functions and Files
Up: 8 Functions and Files
Next: 8.2 Formatted Input/Output
Previous Page: 8 Functions and Files
Next Page: 8.1.1 Character Processing Routines
We have already used several I/O routines from the standard library: scanf(), printf(), getchar() and putchar(). Many other useful routines are provided in one or more libraries supplied with the compiler or in header files. When a function in one of these libraries is used, the name of the library must be supplied to the linker. Otherwise, the linker is unable to resolve the reference to that function. If the function resides in the standard library, the linker does not need to be supplied the name. The linker always searches the standard library by default for any unresolved functions used in the program.
Standard header files supplied with the compiler declare function prototypes for standard library functions in several categories. They also define data types, symbolic constants, and macros. Header files must be included in the source program if any of the definitions, macros, or function prototypes declared in them are to be used.
Many of the functions we have defined in our example programs are available either as standard macros in a header file or as functions in the standard library. We could have used these standard routines in many of our examples. However, we wrote our own versions because it is instructive to see how functions are written.
The following are descriptions of some of the commonly used routines. Similar descriptions of other routines will be provided as we use them. A listing of ANSI standard library routines is provided in Appendix C. It must be understood that the standard is a suggested standard, and all vendors of C compilers may not follow the suggested standard exactly.
The listing below specifies what header file must be included, if any, before the routine listed may be used. It also specifies which file contains the prototypes, if applicable.