Monday 25 August 2014

Filled Under: ,

C Program to Create Your Own Header File in C Programming

Share
C Program to Create Your Own Header File in C Programming


C Program to Create Your Own Header File in C Programming

Step 1: Make a user defined function.
   
   int add(int x,int y)
    {return (x+y);}

  • write only function definition

Step 2: Save code
  
  •    save the above code with extension .h.
           (for example myheader.h)
  • compile if required
Step 3: write main program
  
#include<stdio.h>
#include"myheader.h"
void main() {
   int num1 = 10, num2 = 10, num3;
   num3 = add(num1, num2);
   printf("Addition of Two numbers : %d", num3);
}



  1. Include Our New Header File .
  2. Instead of writing < myheader.h> use this terminology “myheader.h”
  3. All the Functions defined in the myheader.h header file are now ready for use .
  4. Directly  call function add(); [ Provide proper parameter and take care of return type ]
Note
  1. While running your program precaution to be taken : Both files [ myheader.h and example.c ] should be in same folder.