gpt4 book ai didi

c - 未定义对 "calcyear"的引用

转载 作者:行者123 更新时间:2023-11-30 21:03:34 25 4
gpt4 key购买 nike

如果您无法通过我为您布置的高级代码来判断,我是编程新手。我正在读一本关于 C 编程的书,我从中复制了这段代码作为练习,但我不知道为什么会出现这样的错误。请帮忙!!!

我收到一条错误,指出 "file: main.c" "message: undefined reference to calcyear"

/*bigyear.c*/

#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 four digit year (YYYY):");
scanf("%d", &year1);

/*calculate the future year and display it*/
year2 = calcYear(year1);

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

return 0;

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


}

最佳答案

main() 函数之外定义 int calcYear(intyear1)

在标准 C 中,您不能在另一个函数中定义一个函数。

关于c - 未定义对 "calcyear"的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24050340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com