-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
93 lines (75 loc) · 1.24 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include<stdio.h>
struct date
{
int d,m,y;
};
struct date d;
int menu_list()
{
int choice;
printf("1: Initiate Date\n 2:Accept Date \n 3:Print Date \n");
printf("\n enter your choice\n");
scanf("%d",&choice);
return choice;
}
void InitDate(struct date* ptdate)
{
d.d=03;
d.m=03;
d.y=2020;
}
/*
void AcceptDateFromConsole(struct date* ptdate)
{
printf("\n");
printf("\nEnter date\n");
scanf("%d %d %d",&d.d,&d.m,&d.y);
}*/
int AcceptDateFromConsole(struct date* ptdate)
{
printf("\n");
printf("\nEnter date\n");
scanf("%d",&d.d);
{
if(d.d>31 || d.d<0)
printf("\n Invalid date \n");
return 0;
}
scanf("%d",&d.m);
if(d.m>12 || d.m<0)
{
printf("\n Invalid date \n");
return 0;
}
scanf("%d",&d.y);
}
void PrintDateOnConsole(struct date* ptdate)
{/*
if(d.d>31 || d.d<0)
printf("\n Invalid date \n");
if(d.m>12 || d.m<0)
printf("\n Invalid date \n");
else*/
printf("\nDate : %d/%d/%d\n",d.d,d.m,d.y);
}
int main(void)
{
struct date* ptdate=0;
int choice,a;
while( ( choice = menu_list( ) ) != 0 )
switch(choice)
{
case 1:
InitDate(ptdate);
break;
case 2:
a=AcceptDateFromConsole(ptdate);
if(a==0)
printf("Invalid date");
break;
case 3:
PrintDateOnConsole(ptdate);
break;
}
return 0;
}