2.5. Multiple Files

Programs do not have to be written in just one file, your code can split up into as many files as you want, if a program is comprised of forty functions you could put each function into a separate file. This is a bit extreme though. Often functions are grouped by topic and put into separate files. Say you were writing a program that worked out the price of a pizza and displayed the result, you could put the calculation functions into one file, the display functions into another and have main() in a third one. The command you would use to compile your program would look something like this:

ciaran@pooh:~/book$ gcc -o pizza_program main.c prices.c display.c
Remember: If you define a function in prices.c and you want to call this function in main.c you must declare the function in main.c.