1

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

Chaithu
  • 39
  • 1
  • 3

1 Answers1

5

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.

Community
  • 1
  • 1
Alok Save
  • 202,538
  • 53
  • 430
  • 533