在编译后面的源代码时遇到以下错误,我不明白为什么。你能解释一下我做错了吗?我在使用之前已经定义了失败方法的签名,但是链接器找不到符号。
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;
}
答案 0 :(得分:0)
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;
}
您的函数名称中有拼写错误。