From 9f69d90153a5324580158ad2e93fedefce708ef2 Mon Sep 17 00:00:00 2001 From: Bohdan Yanchyk Date: Thu, 26 Mar 2020 21:38:29 +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 | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/du3/program.c b/du3/program.c index 96f21f6..40e95a5 100644 --- a/du3/program.c +++ b/du3/program.c @@ -10,12 +10,42 @@ int main() char dateStr[11]; struct tm t; + + fgets(dateStr, 11, stdin); - strptime(dateStr, "%d.%m.%Y", &t); + char* res = strptime(dateStr, "%d.%m.%Y", &t); + if (res == NULL) { + printf("error: can't parse date!\n"); + return 1; + } t.tm_mday += 7; + t.tm_sec = 0; + t.tm_min = 0; + t.tm_hour = 0; + + time_t mid = mktime(&t); + // printf("%ld", (long)mid); + struct tm* t2 = localtime(&mid); + if(t2->tm_mon + 1 < 10){ + printf(" %d.0%d.%d\n\n", t2->tm_mday, t2->tm_mon + 1, t2->tm_year + 1900); + } else{ + printf(" %d.%d.%d\n\n", t2->tm_mday, t2->tm_mon + 1, t2->tm_year + 1900); + } + return 0; + /*if (time == (time_t)-1) { + printf("fails with error: can't convert date to time!\n"); + return 1; + }*/ + + //t2 = localtime(&sec); + + /*time(&timer); + double seconds = difftime(timer,mktime(&t)); + printf("%.f", seconds); + return 0; if(t.tm_mon + 1 < 10){ printf(" %d.0%d.%d\n\n", t.tm_mday, t.tm_mon + 1, t.tm_year + 1900); } else{ @@ -25,5 +55,5 @@ int main() exit(EXIT_SUCCESS); - return 0; + return 0;*/ }