From e7a637e7747be60fd9231aace18bed9134de2892 Mon Sep 17 00:00:00 2001 From: Vladyslav Korzun Date: Thu, 23 Mar 2023 17:19:09 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB(=D0=B0)=20?= =?UTF-8?q?'a1/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a1/program.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 a1/program.c diff --git a/a1/program.c b/a1/program.c new file mode 100644 index 0000000..7abdb95 --- /dev/null +++ b/a1/program.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#define LINE_SIZE 150 + +int main() { + char znaky[LINE_SIZE]; + memset(znaky, 0, LINE_SIZE); + char* r = NULL; + int dd = 0; + int mm = 0; + int yyyy = 0; + char buffer [LINE_SIZE]; + char *koniec_cisla = NULL; + char* zaciatok_cisla = znaky; + int cislo = 0; + int counter = 0; + while ((r = fgets(znaky, LINE_SIZE, stdin)) != NULL) { + if (feof(stdin)) { + break; + } + zaciatok_cisla = znaky; + counter = 0; + while (*zaciatok_cisla != '\0') { + cislo = strtol(zaciatok_cisla, &koniec_cisla, 10); + if (zaciatok_cisla == koniec_cisla) { + break; + } else { + if (counter == 0) { + dd = cislo; + } else if (counter == 1) { + mm = cislo; + } else if (counter == 2) { + yyyy = cislo; + } + counter++; + zaciatok_cisla = koniec_cisla + 1; + } + } + //printf("%d %d %d\n", dd, mm, yyyy); + time_t t = time(NULL); + struct tm *tm_date = localtime(&t); + tm_date->tm_mday = dd + 7; + tm_date->tm_mon = mm - 1; + tm_date->tm_year = yyyy - 1900; + //printf("%d %d %d\n", tm_date->tm_mday, tm_date->tm_mon, tm_date->tm_year); + time_t daja = mktime(tm_date); + //printf("%ld", daja); + struct tm *tm_churka = localtime(&daja); + + strftime(buffer, LINE_SIZE, "%e.%m.%Y", tm_churka); + for(int i = 0; i < LINE_SIZE; i++){ + if(buffer[i] == ' '){ + buffer[i] = 127; + } + } + if(buffer[0] == 0){ + buffer[0] = 127; + } + if(buffer[3] == 48){ + buffer[3] = 127; + } + puts(buffer); + } + return 0; +}