Using header files for declarations and source files for definitions
The two types of files we will use to group functions are header files and source code files – or, more simply, just source files. Nearly all of the programs we have created thus far have been single-file source files that have included struct
and enum
definitions, typedef
keywords, function prototypes, and functions. This is not typical in C programming; we have only been doing this to keep our programs more condensed. It is far more typical for C programs to consist of the main source file – where the main()
function is defined – and one or more header files and auxiliary source files. The sortNames().c
, nameList.h
, and nameList.c
programs are typical examples of common C programs.
Whenever the preprocessor sees the #include
directive, which must be followed by a filename, it opens that file and reads it into the input stream for compilation at that location, just as if...