2016-09-29 4 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

Typo。関数は '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

関連する問題