gpt4 book ai didi

c - 编译C程序时 undefined symbol

转载 作者:行者123 更新时间:2023-11-30 19:37:31 24 4
gpt4 key购买 nike

编译下面的源代码时出现以下错误,我不明白为什么。你能解释一下我做错了什么吗?我在使用失败方法之前已经定义了它的签名,但是链接器找不到该符号。

Undefined symbols for architecture x86_64:
"_numberOfDays", referenced from:
_main in determinetomorrow-240382.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

#include <stdio.h>
#include <stdbool.h>

struct Date
{
int month;
int day;
int year;
};

int numberOfDays(struct Date);
bool isLeapYear(struct Date);

int main (void) {


struct Date today, tomorrow;
printf("Enter todays date int format (mm dd yyyy): ");
scanf("%i%i%i", &today.month, &today.day, &today.year);

if(today.day != numberOfDays(today)) {
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
} else if(today.month == 12) {
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year + 1;
} else {
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}

printf("Tomorrow's date is %i/%i/%.2i. \n", tomorrow.month, tomorrow.day, tomorrow.year % 100);

return 0;
}

int numberOfDay(struct Date d) {
int days;
const int daysPerMonth[12] =
{31,28,31,30,31,30,31,31,30,31,30,31};
if(isLeapYear(d) == true && d.month == 2)
days = 29;
else
days = daysPerMonth[d.month - 1];

return days;
}

bool isLeapYear(struct Date d) {
bool leapYearFlag;

if((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
leapYearFlag = true;
else
leapYearFlag = false;

return leapYearFlag;
}

最佳答案

int numberOfDays(struct Date);

int numberOfDay(struct Date d) {
int days;
const int daysPerMonth[12] =
{31,28,31,30,31,30,31,31,30,31,30,31};
if(isLeapYear(d) == true && d.month == 2)
days = 29;
else
days = daysPerMonth[d.month - 1];

return days;
}

您的函数名称有拼写错误。

关于c - 编译C程序时 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39761178/

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