How To Make Your Own Header File in Turbo C/C++

STEP 1: create new file (FILE > NEW) and write following syntax in it………….

#ifndef<space>__AMIT_H  //NAME OF YOUR HEADER FILE
#define<space>__AMIT_H
int factorial(int  num) //define your function directly
{
int i,f=1;
for(i=n;i>=1;i–)
f*=i;
return(f);
}
#endif
/* if you wnt to print somethi g in function you would require printf( ) so you can include stdio.h in function definition also
STEP 2: SAVE THIS FILE AS ANKIT.H  IN INCLUDE FOLDER OF TC  //YOU CAN USE ANY NAME //DEFINED ABOVE

#ifndef<space>__AMIT_H  //NAME OF YOUR HEADER FILE
 #define<space>__AMIT_H
#include<stdio.h>
………………………………….
…………………
*/Now you can call your Header file like other files.
#include<ankit.h>  //your header file name
#include<stdio.h>
#include<conio.h>
void main( )
{ int c;
clrscr( );
c=factorial(5);
printf(“factorial is %d”,c);  //change code accordingly in cpp
getch( );
}
Advertisements