关于#include 的试验(打代码新手),不知道这样行不行得通,如果这样不行那怎么改才 ok? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
creater17
V2EX    程序员

关于#include 的试验(打代码新手),不知道这样行不行得通,如果这样不行那怎么改才 ok?

 
  •   creater17 2016-06-28 18:09:37 +08:00 2620 次点击
    这是一个创建于 3472 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #include <stdio.h>
    #define TARGET_AGE 88

    int year1, year2;

    int calcYear (int year1);

    int main (void)
    {
    printf("What year was the subject born?");
    printf("Enter as a 4-digit year (YYYY): ");
    scanf(" %d", &year1);

    year2= calcYear(year1);

    printf("Someone born in %d will be %d in %d.",
    year1, TARGET_AGE, year2);

    system("pause");
    return 0;
    }

    int calcYear(int year1)
    {
    return (year1 + TARGET_AGE);
    }
    把以上内容分为下面的两部分(以上的是书里的,下列的两部分由本人自己编辑)
    /*test.c*/
    #define TARGET_AGE 88

    int year1;

    int calcYear(int year1);

    int main (void)
    {
    int calcYear(int year1);
    {
    return (year1 + TARGET_AGE);
    }
    }

    /*include.c*/
    #include <stdio.h>
    #include <test.h>
    #define TARGET_AGE 88

    int year1, year2;

    int calcYear(int year1);

    int main (void)
    {
    printf ("What year was the subject born? ");
    printf ("Enter as a 4-digit year (YYYY):");
    scanf(" %d ", &year1);

    year2 = calcYear(year1);

    printf("Someone born in %d will be %d in %d.",
    year1, TARGET_AGE, year2);
    return 0;
    }
    如果我把 test.c 加入到 C 编译器的库函数里后(这个不知道行不,或者自己创建函数库?),再编辑 include.c 并编译,这样可以成功执行吗?
    7 条回复    2016-06-29 10:16:59 +08:00
    wsy2220
        1
    wsy2220  
       2016-06-28 20:14:30 +08:00
    #include 就是单纯的文本替换
    creater17
        2
    creater17  
    OP
       2016-06-28 21:18:48 +08:00
    @wsy2220 我还是不太明白
    creater17
        3
    creater17  
    OP
       2016-06-28 22:34:07 +08:00
    我这描述可能有问题,求指教
    sean10
        4
    sean10  
       2016-06-28 23:36:35 +08:00 via iPhone
    建议你去看下 c 的工程是怎么建立的,看下头文件是怎么回事还有多文件编译
    sean10
        5
    sean10  
       2016-06-28 23:39:35 +08:00 via iPhone
    你发的帖子都是能在搜索引擎中搜到的问题……不知道你用的是什么参考书,不过我想应该都有提到编译流程,数据类型转换之类的名词,善用这些名词去搜吧
    ecnelises
        6
    ecnelises  
       2016-06-29 08:12:31 +08:00 via iPhone
    你的 test.h 在哪
    jasonlz
        7
    jasonlz  
       2016-06-29 10:16:59 +08:00
    函数库也不是.c 文件啊,是.h 和编译好的 lib 文件
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     932 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 22:32 PVG 06:32 LAX 14:32 JFK 17:32
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86