zoukankan      html  css  js  c++  java
  • windows下C语言头文件的运用

    头文件 singnext.dingswords

    printf("终止我每丝呼吸,让心灵穿透所有的秘密
    ");

    头文件 singtocj.h

    printf("当无数的日月沧桑后,你会在谁身旁?
    ");

    头文件 myhead.h

    #include <stdio.h>
    #include <Windows.h>
    
    
        int a = 6000;
        int b = 10000;

    头文件 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
    ", a, b);
        printf("共计%d
    ", a+b);
        printf("另外还有%f元努力训练奖励
    ", c);
        getchar();
    }

    点评,以上代码显示了头文件(xx.h)文件的调用,这很像python from xx.py import xxx的模块调用过程。需要注意的是头文件貌似不支持自定义函数;声明 #include “你定义的头文件”可以出现在程序文件的任何位置,就像主程序文件使用的那样。

    头文件和主程序文件部署目录如下图:

    运行结果

    陷阱:头文件重复引用

    假如对主程序文件作如下更改----第8行引入头文件myhead.h:

     1 #include <stdio.h>
     2 #include <Windows.h>
     3 
     4 void main()
     5 {
     6     #include "singnext.dingswords"
     7     #include "singtocj.h"
     8     #include "myhead.h"
     9     #include "calresult.h"
    10     printf("小烤肠快回来吧,老张决定这个月发你工资%d,另外还有你比赛夺冠的奖金%d
    ", a, b);
    11     printf("共计%d
    ", a+b);
    12     printf("另外还有%f元努力训练奖励
    ", c);
    13     getchar();
    14 }

    则会报错提示多次初始化,其原因在于calresult.h引入了myhead.h主程序再次引用构成了对文件中变量的多次引用!解决方案是注释掉上述代码第8行

  • 相关阅读:
    .NET实现Excel文件的读写 未测试
    权限管理设计
    struts1中配置应用
    POJ 2139 Six Degrees of Cowvin Bacon(floyd)
    POJ 1751 Highways
    POJ 1698 Alice's Chance
    POJ 1018 Communication System
    POJ 1050 To the Max
    POJ 1002 4873279
    POJ 3084 Panic Room
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/9468526.html
Copyright © 2011-2022 走看看