C语言里怎样建立头文件(转)

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

举例(程序已调试可以运行非常简单楼主有什么疑问可以交流交流):

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); }

      }

posted @ 2012-07-31 22:36  Drobobls  阅读(333)  评论(0)    收藏  举报