Understanding multi-file programs
Before we get into the nitty-gritty of the differences between source files and header files, we need to understand why we need to have multiple source files at all.
In Chapter 23, Using File Input and File Output, we saw how some of the functions in the program we looked at pertained only to opening and closing files, and some of the functions pertained only to manipulating a linked list. We used the sortNames.c
file to define the usage()
, getName()
, putName()
, trimStr()
, and, of course, main()
functions. Each of these functions deals with some detail of input and output. Although you could argue that trimStr()
belongs more logically in a string-handling source code file, we used it here to clean up the string from getName()
, so here it stays. To sort the names, we used the functions that were declared in nameList.h
and defined in nameList.c
. These functions only dealt with the linked list structure. Since these functions were...