![]() ![]() | structures/dates.c - Et dato program med en funktion, date-before, der vurderer om en dato kommer før en anden dato. | Lektion 12 - slide 10 : 36 Program 1 |
#include <stdio.h> enum weekday {sunday, monday, tuesday, wednesday, thursday, friday, saturday}; typedef enum weekday weekday; struct date { weekday day_of_week; int day; int month; int year; }; typedef struct date date; /* Is date d1 less than date d2 */ int date_before(date d1, date d2){ return (d1.year < d2.year) || (d1.year == d2.year && d1.month < d2.month) || (d1.year == d2.year && d1.month == d2.month && d1.day < d2.day); } int main(void) { date today = {tuesday, 8, 11, 2011}; date tomorrow = {wednesday, 9, 11, 2011}; if (date_before(today, tomorrow)) printf("OK\n"); else printf("Problems\n"); return 0; }