#include <stdio.h>
typedef struct {
int hour, minute, second;
} time;
time
new_time (time time_of_day, int elapsed_secs)
{
int new_hr, new_min, new_sec;
new_sec = time_of_day.second + elapsed_secs;
time_of_day.second = new_sec % 60;
new_min = time_of_day.minute + new_sec / 60;
time_of_day.minute = new_min % 60;
new_hr = time_of_day.hour + new_min / 60;
time_of_day.hour = new_hr % 24;
return (time_of_day);
}
int
main (void)
{
int h = 10, m = 15, s = 42;
time now;
now.hour = h;
now.minute = m;
now.second = s;
int nsecs = 2720;
printf ("Current time: %02d:%02d:%02d\n", now.hour, now.minute, now.second);
now = new_time (now, nsecs);
printf ("Current time: %02d:%02d:%02d\n", now.hour, now.minute, now.second);
}