When the pre-processor sees the #include directive it looks for a file with the name which follows and opens that file. It then passes the contents of that file to the compiler.

At the end of the include file it continues with the current source file. The file that you include can also contain #include directives and the pre-processor will nest them as required.

#include "menu.h"

This would cause the pre-processor to look for a file called menu.h. If this file exists it is included at this point. If it doesn't you are rewarded with:

line    2:
Can not find input file 'menu.h'

line    2:
Can't open include file menu.h

Note that I have used the language extension ".h". This is a convention, in that menu is a header file. We will look at header files later in the course, when we consider how to build bigger projects.

Enclosing the name in <> tells the pre-processor to look in a special system include area for the file. This is where standard definition files for all the C run time library routines are kept. BoostC doesn't provide any standard library files but larger C systems do. A popular set of library routines which is used in many programs is the STandarD Input/Output functions, or STDIO. This supports the input and output of numbers and keypresses, as well as providing access to files. In many programs you will see the include below:

#include <stdio.h>

On the right you can see the pre-processor in action. If the files menu.h and main.c have the contents shown you can see the sequence of lines which the compiler is given.

 

menu.h

mline1
mline2
mline3

main.c.

linea
#include "menu.h"
lineb

COMPILER

linea
mline1
mline2
mline3
lineb