File inclusion in c
File inclusion in C programming means adding the source content of one file to another file. This is usually done using the #include preprocessor directive. Here file inclusion is mainly used to manage large program projects, in which the same program source code is divided into several files. This makes it easier to manage and maintain file inclusion.

Types of File Inclusion in C Programming
There are two main types of file inclusion in C programming.
Standard library inclusion – Here you can add standard library header files to your macros program.
User-defined file inclusion – Here you can add user-defined header files to the macros program.
Inclusion of standard library in macros program.
Standard library files are added using angle brackets (< >). You add these files from standard system directories.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Inclusion of user-defined file in C macros.
User defined files in C macros are added using double quotes symbol (” “). These files are first added from the current directory and then from the standard system directory location.
#include “userdefineheaderfile.h”
Using header files in C macros Example.
So let’s create a simple project in C program with one main file and one header file.
Header file userdefineheaderfile.h
#ifndef USERDEFINEHEADER_H
#define USERDEFINEHEADER_H
void printMessage();
#endif // USERDEFINEHEADER_H
C Source File Header File (USERDEFINEHEADER_H)
#include <stdio.h>
#include “USERDEFINEHEADER_H”
void printMessage() {
printf(“\n let view the header file”);
}
Main File (main.c)
#include “USERDEFINEHEADER_H”
int main() {
printMessage();
return 0;
}
Program explanation given above.
Include guards in program – The #ifndef, #define, and #endif directives in the header file (USERDEFINEHEADER_H) are used to prevent inclusion of the same file in multiple programs. Add this as a “guard” in the program.
Function declaration – Here declare the function printMessage() in your user defined header file (USERDEFINEHEADER_H).
Function definition – The header file is added to the source file (USERDEFINEHEADER_H) and defines the printMessage() function.
Main file – Here the header file is added to the main file (main.c), and calls the printMessage() function in the program.
Compiling multiple files in a C program.
To compile a program with multiple source files in C, you need to compile each source file separately and then combine them together.
Using the #include standard directive in C macros in detail.
Order of file inclusion – The order in which files are added to a C program can impact the program. Generally, standard library header files are added first, followed by user defined header files.
Relative path to file – You can use relative path to add files located in different header file directories to your current program.
#include “../include/USERDEFINEHEADER_H”
File absolute path – Although less common, you can also use absolute paths in your C program.
#include “/home/user/project/include/USERDEFINEHEADER_H”
Header file nested inclusion.
Header files in any C program can contain other header files. Be a little careful with header file nested inclusion to avoid circular dependencies and multiple inclusion.
USERDEFINEHEADER_H 1 (USERDEFINEHEADER_.h)
#ifndef USERDEFINEHEADER_H
#define USERDEFINEHEADER_H
#include “USERDEFINEHEADER.h”
void function1();
#endif // USERDEFINEHEADER_H
Header file USERDEFINEHEADER_H 2 (USERDEFINEHEADER2.h)
#ifndef USERDEFINEHEADER2_H
#define USERDEFINEHEADER_H2_H
void function2();
#endif // USERDEFINEHEADER2_H
source file (main.c)
#include “USERDEFINEHEADER.h”
int main() {
func1();
func2();
return 0;
}
Math Library Practical Example in C Program.
Here we create a small math library with different header and source files depending on our specific programming need.
Header file (mathlibrary.h)
#ifndef MATHLIBRARY_H
#define MATHLIBRARY_H
int total(int p, int q);
int minus(int p, int q);
#endif // MATHLIBRARY_H
Source File (MATHLIBRARY.c)
#include “MATHLIBRARY.h”
int total(int p, int q) {
return p + q;
}
int minus(int p, int q) {
return p – q;
}
Main File (main.c)
#include <stdio.h>
#include “MATHLIBRARY.h”
int main() {
int m = 2, n = 6;
printf(“\n the Add value is – %d”, total(m, n));
printf(“\n the Subtract value is – %d”, minus(m, n));
return 0;
}