How to Create your own Header file in C

[4839 views]




In order to create your own header file, we create a function and save it with .h extension. This file contains only function and nothing else.

In the Main file which you have to save as .c extension and where you want that function to work. We will write a line #include"filename.h" use the function same as it is declared in the same file.

create your own header file in C

Main Program (Save with .c extension):

#include<stdio.h> #include"factorial.h" int main() { int n, ans; printf("Enter a number to find it's factorial:"); scanf("%d", & n); ans = fact(n); printf("%d", ans); }


Header File (Save as factorial.h)

int fact(int a) { if (a == 1) return 1; else return a * fact(a - 1); }


That's it! You have learnt how to create your own header file and how to use.

Happy Coding!

                 





Comments








Search
Have Technical Doubts????


Hot Deals ends in





Join Today to Earn $100 Joining Bonus




Technical Quiz:



Search Tags

    Create Header File in C programming language