From df0e5738df55544c885801968028e01c13ceb702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Szab=C3=B3?= Date: Fri, 27 Mar 2020 09:23:26 +0100 Subject: [PATCH] 1 --- du3/program.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 du3/program.c 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; +}