Created
August 28, 2012 06:25
-
-
Save anonymous/3495461 to your computer and use it in GitHub Desktop.
friday 13 in C (using time.h)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ANSI-C version */ | |
#include <stdio.h> | |
#include <time.h> | |
#define YEAR_ITR 5 | |
#define MONT_ITR 12 | |
int main(int argc, char *argv[]) | |
{ | |
time_t raw_time; | |
struct tm *p; | |
int y = 0, m = 0; | |
time(&raw_time); | |
p = gmtime(&raw_time); | |
p->tm_isdst = -1; | |
p->tm_mday = 13; | |
for (y = 0; y < YEAR_ITR; y++){ | |
p->tm_year += y; | |
for (m = 0; m < MONT_ITR; m++){ | |
p->tm_mon = m; | |
if (mktime(p) == -1){ | |
printf("Error getting time\n"); | |
break; | |
} | |
if (p->tm_wday == 5) | |
printf("%s\n", asctime(p)); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment