demo.c (447B)
1 #include <stdio.h> 2 #include <time.h> 3 4 int output(int hour, int min, int sec) { 5 printf("Current time: %d:%d:%d \n", hour, min, sec); 6 } 7 8 int main(int argc, char** argv) { 9 struct timespec timer = { 0, 700000000 }; 10 time_t datetime; 11 // see /usr/include/bits/types/struct_tm.h 12 struct tm i; 13 14 for (;;) { 15 datetime = time(NULL); 16 localtime_r(&datetime, &i); 17 output(i.tm_hour, i.tm_min, i.tm_sec); 18 nanosleep(&timer, &timer); 19 } 20 }