17 fputs(
"usage: weekday YYYY-MM-DD\n", stderr);
21main(
int argc,
char *argv[])
38 if ((temp = strtok(argv[1],
"-")) == NULL)
39 err(
"bad date: no year");
40 else if ((year = atoi(temp)) == 0)
41 err(
"bad date: invalid year");
43 if ((temp = strtok(NULL,
"-")) == NULL)
44 err(
"bad date: no month");
45 else if ((month = atoi(temp)) == 0)
46 err(
"bad date: invalid month");
48 if ((temp = strtok(NULL,
"-")) == NULL)
49 err(
"bad date: no day");
50 else if ((day = atoi(temp)) == 0)
51 err(
"bad date: invalid day");
54 tm.tm_year = year - 1900;
55 tm.tm_mon = month - 1;
58 if (mktime(&tm) == (time_t)-1)
61 strftime(linebuf,
sizeof(linebuf),
"%Y-%m-%d: %A", &tm);
char * program_invocation_name
Global value for the program's name.
void err(const char *fmt,...)
Prints a formatted error message to stderr and exits.