Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how do i make a header file and use it in another program

+3 votes
asked Sep 2, 2020 by atulsangahvi (200 points)
Where my header.h file needs to be stored so that i can call it?

3 Answers

0 votes
answered Sep 5, 2020 by xDELLx (10,500 points)

For small programs, the best place is current directory ,ie same directory as the c file.

But this can be customised using compiler switches.Complier can be "informed" t olook for header files in certain paths where we want/have stored header files.Compiler switches give us the flexibilty to provide a host of paths , where the header files can be placed.

On GCC, -I (uppercase i) switch can be supplied when compiling your program.

gcc abc.c -I /home/mint

MS Visual Studio also provides the same flexiblity , you can explore this... I am rusty with MS tools.

0 votes
answered Sep 19, 2020 by akash singh yadav (180 points)
it stored in the library of programing file
0 votes
answered Aug 29, 2021 by gordd (140 points)

For me, I found the magic was to include the path of the current project, i.e. './' in the include directive that needs to reference your project's myheader.h file. For example:

#include "./myheader.h"

Note, the #ifndef ... #endif guards around the body of the .h file seemed to make the file invisible again, so I took them out for onlinegdb. YMMV.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...