我正在编译我的程序,我收到以下两个错误:
prog1.c:64:17: error: expected expression
timeUpdate (struct dateAndTime orig);
^
prog1.c:67:20: error: expected expression
dateUpdate(struct dateAndTime orig);
^
我已经读过这样的错误可能是隐形空间中容易错过的细节的结果,但我找不到任何错误。这是我的代码:
#include <stdio.h>
struct date {
int month;
int day;
int year;
};
struct time {
int hour;
int minutes;
int seconds;
};
struct dateAndTime {
struct date sdate;
struct time stime;
};
struct time timeUpdate (struct time now) {
now.seconds++;
if (now.seconds == 60) { //next minute
now.seconds = 0;
now.minutes++;
if (now.minutes == 60) { //next hour
now.minutes = 0;
now.hour++;
if (now.hour == 24) //midnight
now.hour = 0;
}
}
return now;
}
struct date dateUpdate (struct date today) {
struct date tomorrow;
int numberOfDays (struct date d);
if (today.day != numberOfDays (today)) {
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
else if (today.month == 12) { //end of year
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year + 1;
}
else { //end of month
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
return tomorrow;
}
struct dateAndTime clockKeeper (struct dateAndTime orig) {
timeUpdate (struct dateAndTime orig);
if (orig.stime.hour == 0) {
dateUpdate(struct dateAndTime orig);
}
return orig;
}
int main (void) {
struct dateAndTime orig;
printf ("Please enter a date (mm/dd/yyyy)\n");
scanf ("%d/%d/%d", &orig.sdate.month, &orig.sdate.day, &orig.sdate.year);
printf ("Please enter a time (hh:mm:ss)\n");
scanf ("%d:%d:%d", &orig.stime.hour, &orig.stime.minutes, &orig.stime.seconds);
clockKeeper(orig);
printf("%d/%d/%d @ %d:%d:%d\n", orig.sdate.month, orig.sdate.day, orig.sdate.year, orig.stime.hour, orig.stime.minutes, orig.stime.seconds);
}
答案 0 :(得分:1)
你想:
timeUpdate (orig);
而不是:
timeUpdate (struct dateAndTime orig);
这与您不写printf(const char* "Hello world!")
或int x = 1; int y = 2; add(int x, int y)
的方式相同。