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

标签 c undefined-reference

如果您无法通过我为您布置的高级代码来判断,我是编程新手。我正在读一本关于 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/

相关文章:

c - 套接字编程中addrinfo名称的 "hints"是什么意思

c - 如何使用递归函数将十进制数转换为二进制数?

c++ - HLS - 使用循环时数组参数接口(interface)不同

c++ - 来自不需要的库的 undefined reference 错误

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

c++ - 无法链接 GLFW3 : undefined references

c - 网络不好的 C 中的 TCP 套接字

c - 多线程链表操作

c - 链接 libavcodec 和 libavformat : Undefined references

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?