C语言如何写头文件?

Python016

C语言如何写头文件?,第1张

/*头文件内容,假设名字是test.h*/

#ifndef MYHEADFILE

#define MYHEADFILE

void InitInterpolation()

void Draw_Border()

void Draw_Background()

void Draw_Gray()

#endif

/*以下是test.c的内容*/

#include "test.h"

/*后面就是各个函数的实现*/

同项目中其他各个文件需要使用这些函数时只需要下面这样一句:

#include "test.h"

千万不要包含.c文件,会出现重复定义问题

/*头文件内容,假设名字是test.h*/

#ifndef MYHEADFILE

#define MYHEADFILE

void InitInterpolation()

void Draw_Border()

void Draw_Background()

void Draw_Gray()

#endif

/*以下是test.c的内容*/

#include "test.h"

/*后面就是各个函数的实现*/

头文件一般用于多个源码的工程,当然,单源码可以写头文件,这个只是一种风格或习惯,一般是程序的声明部分写在.h中,如你的

char mainmenu(void)

char getBookType (void)

char bookItem (void)

int getBookNumber(void)

还有就是fiction,nonFiction的声明,可写成

extern int fiction

extern int nonfiction