Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can I have some detailed explanation of creating a own header file in C language.

What I have tried:

I tried it my won but the result was not much effective.
Updated 19-Jul-18 5:15am
CPallini 19-Jul-18 6:16am    
What is a 'own header file'? Please elaborate.
Richard MacCutchan 19-Jul-18 11:01am    
Easy, just use a text editor.

However, I suspect the actual question you want answered is something a little more complicated. Please edit your question and try to explain exactly what problem you are trying to solve.

It depends on exactly what editor and so forth you use, but it's very simple: just create a file with the ".h" extension and fill it with your function prototypes, constant definitions, and so forth.

See here: C Header Files[^]
Share this answer
It is hard to give a detailed explanation without knowing what the header file should contain at all.

Note also the the "creation" of a header file is nothing else than the creation of a text file.

In general, header files should contain declarations (like specifying names and types) and source files should contain definitions (implementations).

A header file is usually "connected" to a source file. That means it contains the declarations for the corresponding source file. It is then included by that source file and any other file (source or header) that needs at least one of the declarations (e.g. when calling a function declared in the header file).

A special case are general header files covering project specific settings that are included by all or most files of a project.

To give some examples you should at least specify if you are using C or C++ (classes) and/or give some examples form your source file. Or show us what you have tried and where it failed.
Share this answer
How do I create own header files in C language

Exactly the same as a .c file.
A header file is here to avoid typing again and again structures declarations and functions prototypes in every .c files that use them.

Imagine: you are on a big project, you have built a bunch of functions that are reused everywhere, you can type the structures declarations and functions prototypes in every .c file.

Then you need to change the structures, in this case you need to edit every single .c file that use it. It is tedious and any error will lead to weird behavior and very difficult to spot bugs.
If you use a .h header file, you have 1 place to change for the whole project.
Share this answer
Creating some header files isnt a good idea, because they wont have much content.

Header files are only declarations, what functions or classes will be implemented or some set of constants. They dont make sense, when implementaion of functions is missing.

You need to Learn C++[^] to use the power of the language.
Share this answer
CHill60 19-Jul-18 10:37am    
I fixed your link for you.
I also disagree with your view. In fact these words are taken from the very link you provided
As programs grow larger and larger (and include more files), it becomes increasingly tedious to have to forward declare every function you want to use that lives in a different file. Wouldn’t it be nice if you could put all your declarations in one place?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900