-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprog.9.5.c
49 lines (36 loc) · 847 Bytes
/
prog.9.5.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
// Program to update the time by one second
#include <stdio.h>
struct time
{
int hour;
int minutes;
int seconds;
};
int main (void)
{
struct time timeUpdate (struct time now);
struct time currentTime, nextTime;
printf ("Enter the time (hh:mm:ss): ");
scanf ("%i:%i:%i", ¤tTime.hour,
¤tTime.minutes, ¤tTime.seconds);
nextTime = timeUpdate (currentTime);
printf ("Updated time is %.2i:%.2i:%.2i\n", nextTime.hour,
nextTime.minutes, nextTime.seconds);
return 0;
}
// Function to update the time by one second
struct time timeUpdate (struct time now)
{
++now.seconds;
if ( now.seconds == 60 ) { // next minute
now.seconds = 0;
++now.minutes;
if ( now.minutes == 60 ) { // next hour
now.minutes = 0;
++now.hour;
if ( now.hour == 24 ) // midnight
now.hour = 0;
}
}
return now;
}