IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CStructures & Linked Lists : Time Structure Type
<10.06>
/* A function to compute an updated time value. */ #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); }
Hergestellt in Deutschland / Made in Germany
Current time: 10:15:42 Current time: 11:01:02
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland