#define __USE_XOPEN #define _GNU_SOURCE #include #include #include #define max_yr 9999 #define min_yr 1900 int isleap(int y) { if (y % 4 != 0) { return 0; } else if (y % 100 != 0) { return 1; } else if (y % 400 != 0) { return 0; } return 1; } int datevalid(int d, int m, int y) { if(y < min_yr || y > max_yr) { return 0; } if(m < 1 || m > 12) { return 0; } if(d < 1 || d > 31) { return 0; } if(m == 2) { if(isleap(y)) { if(d <= 29) { return 1; } } else { return 0; } } if ( m == 4 || m == 6 || m == 9 || m == 11 ) { if(d <= 30) { return 1; } else { return 0; } } return 1; } int main() { char buffer[20]; struct tm tm = {0}; char *retval = fgets(buffer, sizeof(buffer), stdin); if (retval == 0) { puts("Neplatny datum"); return 0; } retval = strptime(buffer, "%e.%m.%-Y", &tm); if (retval == 0 || datevalid(tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900) == 0) { puts("Neplatny datum"); return 0; } tm.tm_isdst = -1; tm.tm_mday += 7; if (mktime(&tm) == -1) { puts("Neplatny datum"); return 0; } strftime(buffer, sizeof(buffer), "%e.%m.%-Y", &tm); puts(buffer); putc('\n', stdout); return 0; }