C语言里怎样建立头文件?

如题所述

新建一个头文件text.h,然后把函数代码拷贝到这个头文件中,以后调用的时候#include
"text.h"j就可以了。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-07-29
举例(程序已调试可以运行非常简单楼主有什么疑问可以交流交流):
header
file:(max.h)
#ifndef
MAX_NUMBER
//
MAX_NUMBER
为任意的
#define
MAX_NUMBER
//
重复定义
#include<stdio.h>
int
max(int
a,int
b);
#endif
source
file:(main.c)
#include"max.h"
//
与头文件名相同
int
main()
{
extern
int
a,b;
int
,c;
printf("Please
input
the
value
of
a:
");
scanf("%d",&a);
printf("Please
input
the
value
of
b:
");
scanf("%d",&b);
c=
max(a,b);
printf("The
max
number
of
%d
and
%d
is
%d!\n",a,b,c);
return
0;
}
source
file:(max.c)
#include"max.h"
//
与头文件名相同
int
a,b;
int
max(int
m,int
n)
{
if(m>=n)
{return
(a);}
else
{
return
(b);
}
}
相似回答