pvjc22/a1/program.c

63 lines
1.3 KiB
C
Raw Normal View History

2022-03-27 14:45:37 +00:00
#include<stdio.h>
2022-03-27 16:57:22 +00:00
#include<string.h>
#include<time.h>
#include<stdlib.h>
2022-03-27 14:45:37 +00:00
int main(){
2022-03-27 17:29:12 +00:00
char Dnes_Datum[300];
2022-03-27 17:18:45 +00:00
int ch=getchar(),counter=0;
2022-03-27 17:37:26 +00:00
int id=0;
2022-03-27 17:35:59 +00:00
for(id=0;ch!=EOF;id++){
2022-03-27 16:57:22 +00:00
if(ch=='.'){
ch=' ';
}
2022-03-27 17:35:59 +00:00
Dnes_Datum[id]=ch;
2022-03-27 17:18:45 +00:00
if(ch=='\n'){
counter++;
}
2022-03-27 16:57:22 +00:00
ch=getchar();
2022-03-27 17:35:59 +00:00
if(Dnes_Datum[id]=='\n'&&ch=='\n'){
2022-03-27 17:18:45 +00:00
break;
}
2022-03-27 16:57:22 +00:00
}
2022-03-31 11:13:17 +00:00
Dnes_Datum[id+1]='\0';
2022-03-27 17:35:59 +00:00
2022-03-27 17:50:02 +00:00
char *start=Dnes_Datum, *end=NULL;
time_t t=time(NULL);
2022-03-27 17:35:59 +00:00
2022-03-31 11:13:17 +00:00
for(int idx=0;idx<counter;idx++){
int d1,d2,d3;
int res=sscanf(start,"%d %d %d",&d1,&d2,&d3);
2022-03-27 16:57:22 +00:00
2022-03-31 14:17:06 +00:00
if(res!=3||d1<=0||d2<=12||d3<1900||d3>2030){
2022-03-31 14:08:47 +00:00
printf("Neplatny datum.\n");
2022-03-31 11:13:17 +00:00
while((*start)!='\n')start++;
start++;
continue;
}
2022-03-27 16:57:22 +00:00
2022-03-27 17:18:45 +00:00
struct tm *D_D;
struct tm *NW_D;
2022-03-27 16:57:22 +00:00
2022-03-27 17:18:45 +00:00
D_D = localtime(&t);
2022-03-27 14:45:37 +00:00
2022-03-27 17:18:45 +00:00
D_D->tm_mday=strtol(start,&end,10);
start=end;
D_D->tm_mon=strtol(start,&end,10)-1;
start=end;
D_D->tm_year=strtol(start,&end,10)-1900;
start=end+1;
time_t nex_week=mktime(D_D)+604800;
NW_D=localtime(&nex_week);
printf("%d.%d.%d\n\n",NW_D->tm_mday, NW_D->tm_mon+1,NW_D->tm_year+1900);
}
return EXIT_SUCCESS;
2022-03-27 16:57:22 +00:00
2022-03-27 14:45:37 +00:00
}
2022-03-27 16:57:22 +00:00