windows下C语言头文件的运用
2024-08-30 14:31:52
头文件 singnext.dingswords
printf("终止我每丝呼吸,让心灵穿透所有的秘密\n");
头文件 singtocj.h
printf("当无数的日月沧桑后,你会在谁身旁?\n");
头文件 myhead.h
#include <stdio.h>
#include <Windows.h> int a = ;
int b = ;
头文件 calresult.h
# include "myhead.h" float c;
c = (a + b)*0.035;
主程序文件
#include <stdio.h>
#include <Windows.h> void main()
{
#include "singnext.dingswords"
#include "singtocj.h"
//#include "myhead.h"
#include "calresult.h"
printf("小烤肠快回来吧,老张决定这个月发你工资%d,另外还有你比赛夺冠的奖金%d\n", a, b);
printf("共计%d\n", a+b);
printf("另外还有%f元努力训练奖励\n", c);
getchar();
}
点评,以上代码显示了头文件(xx.h)文件的调用,这很像python from xx.py import xxx的模块调用过程。需要注意的是头文件貌似不支持自定义函数;声明 #include “你定义的头文件”可以出现在程序文件的任何位置,就像主程序文件使用的那样。
头文件和主程序文件部署目录如下图:
运行结果
陷阱:头文件重复引用
假如对主程序文件作如下更改----第8行引入头文件myhead.h:
#include <stdio.h>
#include <Windows.h> void main()
{
#include "singnext.dingswords"
#include "singtocj.h"
#include "myhead.h"
#include "calresult.h"
printf("小烤肠快回来吧,老张决定这个月发你工资%d,另外还有你比赛夺冠的奖金%d\n", a, b);
printf("共计%d\n", a+b);
printf("另外还有%f元努力训练奖励\n", c);
getchar();
}
则会报错提示多次初始化,其原因在于calresult.h引入了myhead.h主程序再次引用构成了对文件中变量的多次引用!解决方案是注释掉上述代码第8行
最新文章
- ORB-SLAM(六)回环检测
- Linux system log avahi-daemon[3733]: Invalid query packet
- 黄聪:远程序桌面登录的.NET(C#)开发
- Java--剑指offer(8)
- [原创]java WEB学习笔记55:Struts2学习之路---详解struts2 中 Action,如何访问web 资源,解耦方式(使用 ActionContext,实现 XxxAware 接口),耦合方式(通过ServletActionContext,通过实现 ServletRequestAware, ServletContextAware 等接口的方式)
- 在PHP中如何获取用户的真实IP
- 【译】 AWK教程指南 11递归程序
- css考核点整理(九)-有几种文字替换方式,之间的优缺点
- 禁用USB存储设备(不重启)
- CSS3动画之旋转魔方盒
- 成都传智播客JDBC视频及讲师介绍
- FineUIMvc
- IOS Swift语言开发 tableView的重用以及自cell的自适应高度
- transition-timing-function 属性
- 关于RecyclerView嵌套导致item复用异常,界面异常的问题
- 15 Django REST Framework 给api添加自定义搜索条件
- centos6.5配置redis服务 很好用谢谢
- Spring Core Programming(Spring核心编程) - AOP Concepts(AOP基本概念)
- 浅谈MVVM
- 使用plumbing命令来深入理解git add和git commit的工作原理