C Programming Tutorial – 7 – Generate a header file and use it:

Note:

  • //make sajjadinfo.h header file and use content of code 1.
  • add #include “sajjadinfo.h”    to your code.
  • “” means just look at current folder.

 

Code 1:    sajjadinfo.h
—————————

#define MYNAME “SB”
#define AGE 33

 

Code 2:
—————————

#include <stdio.h>
#include <stdlib.h>

#include “sajjadinfo.h”     // we create a Header file . “” means just look at current folder.

int main()
{

int HalfOfMyAge=(AGE/2) ;                              // we used sajjadinfo.h file constant data (AGE)
printf(“Half of age of %s is %d \n”, MYNAME , HalfOfMyAge);  // we used sajjadinfo.h file constant data (MYNAME)

return 0;

}