編譯器是給我的錯誤信息上靜態聲明如下非靜態聲明的錯誤消息
line 20: "static declaration of ‘timeDifference’ follows non-static declaration"
然後又是一個在
line 12: "previous declaration of ‘timeDifference’ was here"
我知道它是與我的功能'時間差異'。這裏是我的代碼:
#include <stdio.h>
struct time
{
int hours;
int minutes;
int seconds;
};
main()
{
int timeDifference (struct time diff);
struct time early, late, difference;
printf ("Enter Start Time hh:mm:ss ");
scanf ("%d:%d:%d", &early.hours, &early.minutes, &early.seconds);
printf ("Enter End Time hh:mm:ss ");
scanf ("%d:%d:%d", &late.hours, &late.minutes, &late.seconds);
int timeDifference (struct time diff)
{
if (late.seconds < early.seconds)
late.seconds += 60;
late.minutes -= 1;
if (late.minutes < early.minutes)
late.minutes += 60;
late.hours -= 1;
if (late.hours < early.hours)
late.hours += 24;
diff.seconds = late.seconds - early.seconds;
diff.minutes = late.minutes - early.minutes;
diff.hours = late.hours - early.hours;
}
return 0;
}
你有函數的原型和定義在'main'的主體中。將原型移動到'main'之前,並將'main'之後的函數移動。 – AntonH
@AntonH原型可以保持在主體內。 – bubble
在嘗試之前先閱讀基本知識。 http://www.tutorialspoint.com/cprogramming/c_functions.htm –