私は構造体をC言語で学習していますが、深夜であるかどうかをテストするために構造体に到達する便利な方法はわかりません。Cで構造体を比較
ラインが構文エラー(error: expected expression
)を持っている "場合":
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 dateAndTime clockKeeper(struct dateAndTime DaT)
{
struct dateAndTime UpdatedDaT = { .stime = timeUpdate(DaT.stime) };
if (UpdatedDaT.stime == { 0, 0, 0})// If midnight
UpdatedDaT.sdate = dateUpdate(DaT.sdate);
else
UpdatedDaT.sdate = DaT.sdate;
return UpdatedDaT;
}
int main(void)
{
struct dateAndTime DaT;
printf("Enter date and time (mm dd yyyy hh:mm:ss): ");
scanf("%i %i %i %i:%i:%i", &DaT.sdate.month, &DaT.sdate.day, &DaT.sdate.year,
&DaT.stime.hour, &DaT.stime.minutes, &DaT.stime.seconds);
struct dateAndTime UpdatedDaT = clockKeeper(DaT);
printf("\nThe UpdatedDaT is %i/%i/%.2i %.2i:%.2i:%.2i\n",
UpdatedDaT.sdate.month, UpdatedDaT.sdate.day, UpdatedDaT.sdate.year,
UpdatedDaT.stime.hour, UpdatedDaT.stime.minutes, UpdatedDaT.stime.seconds);
return 0;
}
ありがとう! @Paul R – Yellowfun