Chaithu
Chaithu

Reputation: 39

header file (.h) creation in c programming

I am new to eclipse, developing c program in eclipse

I am creating multiple source files in same project, could some one help me to create .h file for main () function and to call in multiple source file

for instance if I have created main.c file, now how to call this main.c into another .c file

Upvotes: 1

Views: 313

Answers (1)

Alok Save
Alok Save

Reputation: 206566

The main() function should not be in a header file. It should be in one and only one .c file.

An example of simple layout can be:

//header.h

#ifndef MY_HEADER <----Notice the Inclusion Guards, read more about them in a good book
#define MY_HEADER

void doSomething();

#endif //MY_HEADER

//header.c

#include "header.h"

void doSomething()
{


}

//Main.c

#include "header.h"

int main(void)
{
    doSomething();
    return 0;
}

But please pick up a good book to learn these basics, You definitely need one.

Upvotes: 5

Related Questions