I have a problem with making header files in c, i get the code written only in main.c and then i have to create a files with extension .h and extension .c but i have no idea how to do it.
I have a problem with making header files in c, i get the code written only in main.c and then i have to create a files with extension .h and extension .c but i have no idea how to do it.
Do you mean how to change the file extensions or what to put inside each? For the first if using windows, you have to uncheck "hide extensions of know file types" in the "folder and search options". Then you'll be able to change extensions manually.
About what to put inside them, it's quite simple. In .h you put the prototypes( declarations ) and in .c you put the implementation( definitions ). Then you need to compile them together,
- either by adding all files to a project ( main.c, example.h & example.c ) and building,
- in cmd by giving all source files to the compiler (gcc main.c example.c ...)
- or by building object files(*.o) for each source with (gcc -c main.c -o main.o) and linking them all together (gcc main.o example.o -o example.exe).
Devoted my life to programming...
I assume you mean how to create a header file and include it into your source file. If so, please see the following tutorial:
C - Header Files tutorial
Well, what confuses me is that when i create a header file i should have that ifndef part automatically created, yet, when i do it, it's just empty file, what should i do to make it appear right after i create header file?