diff --git a/du3/program.c b/du3/program.c new file mode 100644 index 0000000..fca5176 --- /dev/null +++ b/du3/program.c @@ -0,0 +1,50 @@ +#include +#include +#define __USE_XOPEN +#include + +int main(int argc, char const *argv[]){ + + char str[50]; + fgets(str, 50, stdin); + struct tm time; + + if(strptime(str, "%d.%m.%Y", &time)==NULL){ + printf("Nespravny datum\n"); + return 0; + } + +int max; + switch(time.tm_mon+1){ + case 2: + if((time.tm_year+1900)%4==0) + max=29; + else + max=28; + break; + case 4: + case 6: + case 9: + case 11: + max=30; + break; + default: + max=31; + } + if(time.tm_mday<1){ + printf("Nespravny datum\n"); + return 0; + } + if(time.tm_mday>max){ + printf("Nespravny datum\n"); + return 0; + } +time_t pouprave = mktime(&time)+604800+3600; + + strftime(str, sizeof(str), "%d.%m.%Y", localtime(&pouprave)); + if(str[0]=='0'){ + str[0]=' '; + } + printf("%s\n\n", str); + return 0; +}