简体   繁体   English

在C编程中创建头文件(.h)

[英]header file (.h) creation in c programming

I am new to eclipse, developing c program in eclipse 我是eclipse的新手,正在eclipse中开发c程序

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 我正在同一项目中创建多个源文件,有人可以帮助我为main()函数创建.h文件并调用多个源文件

for instance if I have created main.c file, now how to call this main.c into another .c file 例如,如果我创建了main.c文件,现在如何将main.c调用到另一个.c文件中

The main() function should not be in a header file. main()函数不应位于头文件中。 It should be in one and only one .c file. 它应该在一个并且只有一个.c文件中。

An example of simple layout can be: 简单布局的示例可以是:

//header.h //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 //header.c

#include "header.h"

void doSomething()
{


}

//Main.c //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. 但是请拿起一本好书来学习这些基础知识,您肯定需要一本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM