Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Header Files - Correct Way to Include

Tags:

People also ask

Which is correct to include header file in C program?

In C language, header files contain the set of predefined standard library functions. You request to use a header file in your program by including it with the C preprocessing directive “#include”. All the header file have a '. h' an extension.

Which is the correct syntax to include header file?

Which of the following is the correct syntax of including a user defined header files in C++? Explanation: C++ uses double quotes to include a user-defined header file. The correct syntax of including user-defined is #include “userdefinedname”.

Does order of header files matter in C?

Ideally, all header files should be self-contained, and inclusion order should not matter. In practice, people often write header files that are not self-contained, and sometimes inclusion order does matter.

How are header files used in C?

A header file is a file with extension . h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.


I am trying to teach myself C Programming and I am using DevC++ for my IDE under Windows XP. I am a little confused on the correct way to call my own Header Files.

I have my main source file called main.c and a separate file for functions called myFunctions.c which I include in main.c using 'include "myFunctions.h" with all my function prototypes residing in this Header file.

myFunctions.c contains two functions one called showDate() and one called showScreen() and both functions can be called from main.c all well and good.

My problems started when I tried to call showDate() from within showScreen() and during compilation/linking it was complaining because I did not have a prototype inside myFunctions.c for showDate().

What I want to know is which of the following do I need to do?

  1. include "myFunctions.h" inside myFunctions.c

  2. Declare the Prototype in both myFunctions.h and myFunctions.c
  3. Declare the prototype in just myFunctions.c only

All of the above seems to correct the compiler error and allow me to call the function bot from main.c and within myFunctions.c but I can not find a definitive source of which is the correct procedure.