How to write my own header file in C?

CServer Side ProgrammingProgramming

Steps to write my own header file in C −

  • Type a code and save it as “sub.h”.
  • Write a main program “subtraction.c” in which −
    • include new header file.
    • Write “sub.h” instead of <sub.h>
    • All the functions in sub.h header are now ready for use.
    • Directly call the function sub().
    • Both “subtraction.c” and “sub.h” should be in same folder.

Sub.h

int sub(int m,int n) {
   return(m-n);
}

subtraction.c

Example

#include<stdio.h>
#include "sub.h"
void main() {
   int a= 7, b= 6, res;
   res = sub(a, b);
   printf("Subtraction of two numbers is: %d", res);
}

After running ”subtraction.c” the output will be −

Output

Subtraction of two numbers is: 1
raja
Published on 18-Jun-2019 08:28:47
Advertisements