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

2016 年 6 月 28 日
 creater17
#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 并编译,这样可以成功执行吗?
2777 次点击
所在节点    程序员
7 条回复
wsy2220
2016 年 6 月 28 日
#include 就是单纯的文本替换
creater17
2016 年 6 月 28 日
@wsy2220 我还是不太明白
creater17
2016 年 6 月 28 日
我这描述可能有问题,求指教
sean10
2016 年 6 月 28 日
建议你去看下 c 的工程是怎么建立的,看下头文件是怎么回事还有多文件编译
sean10
2016 年 6 月 28 日
你发的帖子都是能在搜索引擎中搜到的问题……不知道你用的是什么参考书,不过我想应该都有提到编译流程,数据类型转换之类的名词,善用这些名词去搜吧
ecnelises
2016 年 6 月 29 日
你的 test.h 在哪
jasonlz
2016 年 6 月 29 日
函数库也不是.c 文件啊,是.h 和编译好的 lib 文件

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/288917

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX