c语言中,如何在头文件中调用某个源文件的函数??

Python059

c语言中,如何在头文件中调用某个源文件的函数??,第1张

file1.c

头文件为file1.h

file2.c

头文件为file2.h

比如file2.c要调用file1.c里的一个函数

首先file2.c里要包含file1.h头文件(file1.h里有file1.c的函数申明)

然后file2.c文件里要有file1.c里的外部函数申明,用extern关键字申明

然后就可以直接file2.c里面调用file1.c里的函数了

可以新建一个头文件,struct.h

#ifndef

STRUCT_H

#define

STRUCT_H

struct

persons

{

char

name[16]

char

sex[6]

char

age[3]

char

bir[5]

char

phnum[18]

char

addr[20]

}

persons[100]

/**********************************************************************************/

typedef

struct

lnode

{

char

name[16]

/*姓名*/

char

sex[6]

/*性别:以man代表男性,woman代表女性*/

char

age[3]

/*年龄*/

char

bir[5]

/*生日,其中前两位数字代表月份,后两位数字代表日期*/

char

phnum[18]

/*电话*/

char

addr[20]

/*地址*/

struct

lnode

*next

}

void

fun()//把函数申明放在头文件中,在.c文件中实现。

#endif