1
This commit is contained in:
		
							parent
							
								
									87f3955187
								
							
						
					
					
						commit
						df0e5738df
					
				
							
								
								
									
										50
									
								
								du3/program.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								du3/program.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#define __USE_XOPEN
 | 
			
		||||
#include <time.h>
 | 
			
		||||
 | 
			
		||||
int main(int argc, char const *argv[]){
 | 
			
		||||
 | 
			
		||||
	char str[50];
 | 
			
		||||
	fgets(str, 50, stdin);
 | 
			
		||||
	struct tm time;
 | 
			
		||||
 | 
			
		||||
	if(strptime(str, "%d.%m.%Y", &time)==NULL){
 | 
			
		||||
		printf("Nespravny datum\n");
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
int max;
 | 
			
		||||
	switch(time.tm_mon+1){
 | 
			
		||||
		case 2:
 | 
			
		||||
			if((time.tm_year+1900)%4==0)
 | 
			
		||||
				max=29;
 | 
			
		||||
			else
 | 
			
		||||
				max=28;
 | 
			
		||||
			break;
 | 
			
		||||
		case 4:
 | 
			
		||||
		case 6:
 | 
			
		||||
		case 9:
 | 
			
		||||
		case 11:
 | 
			
		||||
			max=30;
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			max=31;
 | 
			
		||||
	}
 | 
			
		||||
	if(time.tm_mday<1){
 | 
			
		||||
		printf("Nespravny datum\n");
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	if(time.tm_mday>max){
 | 
			
		||||
		printf("Nespravny datum\n");
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
time_t pouprave = mktime(&time)+604800+3600;
 | 
			
		||||
 | 
			
		||||
	strftime(str, sizeof(str), "%d.%m.%Y", localtime(&pouprave));
 | 
			
		||||
	if(str[0]=='0'){
 | 
			
		||||
		str[0]=' ';
 | 
			
		||||
	}
 | 
			
		||||
	printf("%s\n\n", str);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user