From c75ad60f3c0fefddb841ff8b51d46153a848c98c Mon Sep 17 00:00:00 2001 From: Bohdan Yanchyk Date: Thu, 26 Mar 2020 22:19:06 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu3/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du3/program.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/du3/program.c b/du3/program.c index 02b7d7e..b2d1e90 100644 --- a/du3/program.c +++ b/du3/program.c @@ -4,15 +4,36 @@ #include #include -int ValidateTime(int hh , int mm , int ss) +int ValidateTime(int dd , int mm , int yy) { - int ret=0; - - if(hh>24) ret=1; - if(mm>60) ret=1; - if(ss>60) ret=1; - - return ret; + int res = 0; + if(yy>=1900 && yy<=9999) + { + //check month + if(mm>=1 && mm<=12) + { + //check days + if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12)) + res = 1; + else if((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11)) + res = 1; + else if((dd>=1 && dd<=28) && (mm==2)) + res = 1; + else if(dd==29 && mm==2 && (yy%400==0 ||(yy%4==0 && yy%100!=0))) + res = 1; + else + res = 0; + } + else + { + res = 0; + } + } + else + { + res = 0; + } + retrun res; } int main() @@ -20,12 +41,13 @@ int main() char dateStr[11]; struct tm t; - int hour = 0, min = 0, secs = 0; + int dd = 0, mm = 0, yy = 0; fgets(dateStr, 11, stdin); - sscanf(dateStr , "%d:%d:%d" , &hour,&min,&secs); - if(!ValidateTime(hour,min,secs)){ + sscanf(dateStr , "%d.%d.%d" , &dd,&mm,&yy); + if(!ValidateTime(dd,mm,yy)){ printf("Nespravny datum\n"); + return 1; } char* res = strptime(dateStr, "%d.%m.%Y", &t); if (res == NULL) {