1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <stdio.h>
#include <time.h>
char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Unknown"};
int main(void)
{
struct tm time_check;
int year, month, day;
/* Input a year, month and day to find the weekday for */
printf("Year: ");
scanf("%d", &year);
printf("Month: ");
scanf("%d", &month);
printf("Day: ");
scanf("%d", &day);
/* load the time_check structure with the data */
time_check.tm_year = year - 1900;
time_check.tm_mon = month - 1;
time_check.tm_mday = day;
time_check.tm_hour = 0;
time_check.tm_min = 0;
time_check.tm_sec = 1;
time_check.tm_isdst = -1;
/* call mktime to fill in the weekday field of the structure */
if (mktime(&time_check) == -1)
time_check.tm_wday = 7;
/* print out the day of the week */
printf("That day is a %s\n", wday[time_check.tm_wday]);
return 0;
} |
Partager