V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
creater17
V2EX  ›  程序员

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

  •  
  •   creater17 · 2016-06-28 18:09:37 +08:00 · 2113 次点击
    这是一个创建于 2864 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #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   ·   我们的愿景   ·   实用小工具   ·   842 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:38 · PVG 03:38 · LAX 12:38 · JFK 15:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.