pvjc23/a1/program.c

92 lines
2.1 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#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;
int che = 0;
while ((r = fgets(znaky, LINE_SIZE, stdin)) != NULL) {
if (feof(stdin)) {
break;
}
if(znaky[0] == '\n'){
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;
if(dd == 0){
che = 1;
}
} else if (counter == 1) {
mm = cislo;
if(mm == 0){
che = 1;
}
} else if (counter == 2) {
yyyy = cislo;
if(yyyy == 0){
che = 1;
}
}
counter++;
zaciatok_cisla = koniec_cisla + 1;
}
}
if(counter != 3 || che == 1){
printf("Neplatny datum.\n");
che = 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] = '&';
}
}
if(buffer[0] == 0){
buffer[0] = '&';
}
if(buffer[3] == 48){
buffer[3] = '&';
}
if(che == 0){
for(int i = 0; i < 10; i++){
if(buffer[i] != '&'){
printf("%c", buffer[i]);
}
}
printf("\n\n");
}
}
return 0;
}