Create Your Own Header File C Program

C Program To Create Your Own Header File in Linux Ubuntu

Learn how to Create your own Header File in C Programming in Linux Ubuntu OS. This guide helps you to make a .h file in C Programming which will be your own customised Header Files and include it in your C Programs using the #include statement. This is the easiest article to guide on How To Create a .h File in C Programming.

What are Header Files?

A Header File consists of Function Definitions, Declarations and Macros that can be used in several C programs. These files are used to eliminate redundancies, inconsistencies and save on time consumption. An include statement is used to import the contents of such header files including Functions and Macro Definitions. There are two types of Header Files in C Programming:

  1. Pre – Defined Header Files in the Compiler Library
  2. Programmer – Defined Header Files

Why The Need of Header Files?

When you are working on a very large scale project in C Programming, you have to write a lot of functions. So, obviously there will be many people working in the same project. It is, therefore, difficult to write all the functions in a single file and keep it updating every other day.

Instead, you can write you own functions in your separate file which is know as Header Files, and then these Header Files can be included in the main program file. This technique therefore helps to ease the debugging, reduce the number of lines of code and thereby, save on time.

Step 1: Create A Header File in C Programming

  • Open the Notepad / gEdit or any other Editor (preferably gEdit)
  • Type the following program which is used to Divide Two Numbers in C Programming

  • Save the file with a .h extension. For instance, let us save it with the name – divi.h. You can save this file at any location in your computer.

Step 2: Write a C Program using your own Header File

  • Again, open the Notepad / gEdit or any other Editor
  • Type the following code in this new program. This code will take Two Numbers from the User and pass it to the division function.
  • Save this program code with a .c extension. For instance, let us give it a name – a.c. You can save this file at any location.

  • If you have created the Header file in a location other than the include folder in C drive then you must use the above version #include”divi.h”. If you use #include<stdio.h>, you program won’t work and it will produce an error.
  • If you include <divi.h>, it tells the compiler to search for the divi.h header file in the Standard C Library Directory. The “divi.h” indicates the compiler to search for the divi.h file in the Current Directory as well as the Standard C Library. Hence, it is always a good option to use the later version with double quotes. If you save the header files in the C Library Directory, then you can use the first version of #include statement.
  • We have used the Division function which is defined in the File divi.h.
  • We do not need to compile or perform any other operations on the Header Files.
  • Now, simply compile and run the a.c file. You will be able to execute the program successfully.


Create Your Own Header File in C Programming in Linux Ubuntu

If you have any compilation error or doubts in this C Program For Creating Your Own Header Files in Ubuntu, let us know about it in the Comment Section below.

Recommended Programs
C Program To Find Day of a given Date
C Program To Display Map of India
C Program To Develop A Calculator Application
C Program To Count Zeros at the End in Factorial of Number
C Program To Print System Time and Date
C Program To Convert Binary Number into Decimal Value
C Program To Shutdown System For Linux Ubuntu

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

13 thoughts on “Create Your Own Header File C Program

  • August 28, 2016 at 8:28 am

    I am using Linux Ubuntu. Where can I can find the GCC Compiler’s Header Files?

    • August 30, 2016 at 8:53 am

      You can find existing Header Files in C Library here: usr/include/

  • August 28, 2016 at 5:27 pm

    Is this header file portable in other OS and Compilers?

    • August 30, 2016 at 8:55 am

      Since there is no need to compile header files, these are normally portable in other OS. However, there may be some implementation differences in different OS and Compilers.

  • August 31, 2016 at 12:43 pm

    Is it compulsory to save the Header Files in C Programming Library Files in the C Drive?

    • August 31, 2016 at 1:38 pm

      No. It is not mandatory. But, if you’re having multiple header files, it is generally a good idea to keep all the header files in one directory / folder.

  • September 2, 2016 at 9:20 am

    This is just an awesome tutorial on creating header files in C programming. Thank you so much. It has helped me to developed a mini project in C programming. This concept of Header files is really good and helps to maintain the source code without much hassles.

  • September 13, 2016 at 11:02 am

    Such a fantastic code. Now, I can start developing my own project. Thanks for this Header file implementation explanation.

  • September 17, 2016 at 10:08 pm

    This was very useful guys,

    Thank you for your help!

  • October 1, 2016 at 2:18 pm

    I can finally now create new and customized header files for my c project. Thanks a lot.

  • October 14, 2016 at 11:46 pm

    If I create a header file in Windows 7, will it work in Mac OS or do I need to make any other modifications?


Join The Discussion