#include #include #include #include struct tm *proceedMonth1stDay(struct tm *t); struct tm *getCurrentLocalTimeStructure(); struct tm *proceedInput(struct tm *t); int proceedCalender(int y, int m, int start); int main() { struct tm *t = proceedMonth1stDay(NULL); printf("\n\n\t\t"); while(1) { proceedCalender(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday + 1); t = proceedInput(t); } return 1; } struct tm *getCurrentLocalTimeStructure() { static time_t currTimeStamp; time(&currTimeStamp); return localtime(&currTimeStamp); } struct tm *proceedMonth1stDay(struct tm *t) { if(t == NULL) t = getCurrentLocalTimeStructure(); t->tm_mday = 1; mktime(t); return t; } struct tm *proceedInput(struct tm *t) { char c; printf("COMMAND : "); c = getchar(); if(c == '1' || c == '[') t->tm_mon--; else if(c == '3' || c == ']') t->tm_mon++; else if(c == '7' || c == '-') t->tm_year--; else if(c == '9' || c == '+') t->tm_year++; else if(c == 'Q' || c == 'q') exit(0); if(t->tm_mon == 12) { t->tm_year++; t->tm_mon = 0; } if(t->tm_mon == -1) { t->tm_year--; t->tm_mon = 11; } return proceedMonth1stDay(t); } int proceedCalender(int y, int m, int start) { static int monthDays[12] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int i; if(((y % 4 == 0) && !(y % 100 == 0)) || (y % 400 == 0)) monthDays[2 - 1] = 29; else monthDays[2 - 1] = 28; printf("\n\n\t\t\t*** CALENDER ***"); printf("\n\n\t\t\t\t\t%4d/%02d", y, m); printf("\n\n\t\tSUN MON TUE WED THU FRI SAT\n\t\t\n\t\t"); for(i = 1; i <= start - 1; i++) printf(" "); for(i = 1; i <= monthDays[m - 1]; i++, start++) { printf("%3d ", i); if(start % 7 == 0) printf("\n\t\t"); } printf("\n\n\t\t"); return 1; }