The second preprocessor directive causes one file to be included in another. The preprocessor command for file inclusion looks like this
# include filename
And it simply causes the entire contents of file name to be inserted into the source code at that point in the program. Of course, this presumes that the file being included exists.
It can be used in two cases:
(1). If we have a very large program. The code is best divided into several different files, each containing a set of related functions. It is a good programming practice to keep different sections of a large program separate. These files are included at the beginning of main program file.
(2). There are some functions and some macro definitions that we need in almost all programs that we write these commonly needed functions and macro definitions can be stored in a file and that can be included in every program we write, which would add all the statements in this file to our program as if we typed them in.
It is common for the files that we are to be included to have a .h extension. This extension stands for header file, possibly because it contains statements which when included go to the head of your program. The prototypes of all the library functions are grouped into different categories and than stored in different header files.
For example, prototypes all mathematics related functions are stored in the header file math.h,prototypes of console input/output functions are stored in the header file conio.h,and so on.
Actually there exists two ways to write #include statement. These are :
# include filename
# include <filename>
The meaning of each of these forms is shown below :
# include goto.h: This command would look for the file goto.h in the current directory as well as the specified list of directories as mentioned in the include search path that might have been set up.
# include <goto.h: This command would look for the file goto.h in the specified list of directories only.
The include search path is nothing but a list of directories that would be searched for the file being included. Different C compilers let you see the search path in different manners. If you are using Turbo C/C ++ compiler, then the search path can be set up by setting Directories from the Options menu. On doing this, a dialogue box appears. In this dialog box against Include Directories we can specify the search path. We can also specify multiple include paths by ;(semicolon) as shown below
c:\tc\lib; c:\mylib ; d:\libfiles
The path can contain maximum of 127 characters. Both relative and absolute paths are valid. For example ..\dir\incfiles is a valid path.
Our email-based homework help and assignment help offers wonderful insights and simulations which help make the subject practical and pertinent. Our tutors at Transtutors.com are extremely qualified and have years of experience providing Computer Science homework help and assignment help.
Please send your problems related to File Inclusion and we will forward it to our tutors for analysis. We will provide you homework help and assignment help without plagiarism in a timely manner at reasonable price without compromising the quality