c语言的.h文件怎么写,c语言自己写一个.h的头文件

首先放上三段简单的源码

main.c 里面的内容

#include"stdio.h"

#include "lib.h"

int main(){

int a,b,c;

printf("请输入a:");

scanf("%d",&a);

printf("\n请输入b:");

scanf("%d",&b);

printf("\n请输入c:");

scanf("%d",&c);

printf("\n%d",max(a,b,c));

}

lib.h  里面的内容

#ifndef LIB_H

#define LIB_H

void displayNarcissistic(void);

int max(int a,int b,int c);

#endif

lib.c  里面的内容

#include "lib.h"

#include "stdio.h"

int max(int a,int b,int c){

int temp;

if (a>b){

temp = a;

a = b;

b = temp;

if (a>c){

temp = a;

a = c;

c = temp;

}else if (b>c){

temp = b;

b = c;

c = temp;

}

}else if (a

if (a>c){

temp = a;

a = c;

c = temp;

}else if (b>c){

temp = b;

b = c;

c = temp;

}

}

return c;

}

当然你可忽略函数里面写的是什么,然而这样在devc++上的编译结果是这样的

365400.html

自然,它的意思是说没有找到max这个函数,咦?这是我们的函数写错了吗?当然不是了,我们需要在devc++中新建项目,将三个文件在一个项目下编译运行。过程如图:

《1》

365400.html

365400.html

《2》

365400.html

365400.html

至此,我们就成功的写了一个自己的头文件,并且用main函数来测试它。



  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值