Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions




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:

[email protected]:~/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.

  Published under the terms of the GNU General Public License Design by Interspire