This Program implements a Digital Clock in C Program Code: /* Program to implement a digital clock */ #include <stdio.h> #include <time.h> int main() { time_t ts, flag = 1; struct tm *ct; system("clear"); printf("\n\n\t Digital Clock - CodeGig.org \n\t "); /* digital clock implementation */ while (1) { /* time() - gives time in seconds */ ts = time(NULL); /* converting time(NULL) o/p to min, sec, hours */ ct = localtime(&ts); /* print the digital clock */ if (flag || ct->tm_min % 59 == 0) { if (!flag) printf("\b\b\b\b\b\b"); printf("%02d:%02d:%02d", ct->tm_hour, ct->tm_min, ct->tm_sec); flag = 0; printf("\b\b"); continue; } if (ct->tm_sec % 59 == 0) { printf("\b\b\b"); printf("%02d:", ct->tm_min); } printf("%02d", ct->tm_sec); printf("\b\b"); } return 0; } Program Output:
Post a Comment