-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime.c
95 lines (81 loc) · 1.49 KB
/
time.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
94
95
/* including header files */
#include<stdio.h>
#include<stdlib.h>
/* struct declaration */
struct time_struct
{
int hour;
int minute;
int second;
};
struct time_struct time;
// setTime(hour, minutes, seconds) : sets time //
void setTime(int h, int m, int s)
{
time.hour = h;
time.minute = m;
time.second = s;
return;
}
// displayTime() : displays time //
void displayTime()
{
printf("%d:%d:%d\n", time.hour, time.minute, time.second);
return;
}
// updateTime() : updates time by 1 second every time called //
void updateTime()
{
time.second += 1;
if(time.second == 60)
{
time.second = 0;
time.minute += 1;
if(time.minute == 60)
{
time.minute = 0;
time.hour += 1;
if(time.hour == 24)
{
time.hour = 0;
}
}
}
return;
}
/* main */
int main()
{
int ch, h, m, s;
/* while loop start */
while(1)
{
printf("Menu : \n");
printf("1. setTime\n2. displayTime\n3. updateTime\n4. Exit\n");
printf("Enter your choice : ");
scanf("%d", &ch);
updateTime();
/* switch start*/
switch(ch)
{
case 1:
printf("Enter hour, min and sec value : ");
scanf("%d %d %d", &h, &m, &s);
setTime(h, m, s);
break;
case 2:
displayTime();
break;
case 3:
updateTime();
break;
case 4:
exit(0);break;
default:
printf("Invalid Choice!\n");
}
/* switch end */
}
/* while loop end */
}
/* main function block end*/