2016-09-29 1 views
-1

다음에 나오는 소스 코드를 컴파일 할 때 다음과 같은 오류가 발생하며 이유를 모르겠습니다. 내가 잘못하고있는 것을 설명해 주시겠습니까? 나는 링커가 심볼을 찾을 수 없지만 그것을 사용하기 전에 실패한 메소드의 서명을 정의했다.C 프로그램을 컴파일 할 때 정의되지 않은 기호

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

오타. 이 함수는'numberOfDays'로 선언되고'numberOfDay'로 정의됩니다. –

답변

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; 
} 

당신은 함수 이름에 오타가 있습니다.

+1

와우는 세부 사항에주의를 기울여야합니다. 완전히 간과했다. – dcrearer

+0

오타가 답을 얻을 자격이 없습니다. –

+0

@RSahu 부적절한 의견 .. 코멘트를받을 자격이 없어. – Inisheer

관련 문제