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

我想把平常用的函数都封装到一个头文件中以便日后直接调用 头文件怎样编写?最好能举例

第1个回答  2011-12-24
举例(程序已调试可以运行非常简单楼主有什么疑问可以交流交流):
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); }
}本回答被提问者采纳
第2个回答  2011-12-24
新建一个头文件text.h,然后把函数代码拷贝到这个头文件中,以后调用的时候#include "text.h"j就可以了。
第3个回答  2011-12-24
这个东西没办法举例,建议看看The C program 这本书
相似回答