Chapter 5

Multiple Files

Up to this point, all of our programs have been written within a single file. There is nothing wrong with this – a C program is just a bunch of functions, and it’s fine to group those functions within a single file. However, as your programs get bigger, it’s nice to physically separate functions into different files. This makes it easier to find certain pieces of your program.

Separating functions also promotes reuse. Right now, if we wanted to reuse a function we’d written in another program, we would have to copy it from our old program to our new one. With multiple files, we can separate the functions we want reused and just link to that file when we want to use them (this is like separating the C library functions and including them when we want to use them).