From aa4299df70269353cdc8e890a08e34795517afd0 Mon Sep 17 00:00:00 2001 From: Devils-judge <98455911+Devils-judge@users.noreply.github.com> Date: Fri, 21 Oct 2022 02:23:45 +0530 Subject: [PATCH] Clock Heyy this is the code for showing real time clock . hope u'll merge it n please add hacktoberfest accepted label to it. Thanks:) --- C/Clock | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 C/Clock diff --git a/C/Clock b/C/Clock new file mode 100644 index 0000000..008af96 --- /dev/null +++ b/C/Clock @@ -0,0 +1,54 @@ +/*This is the code for showing real time clock. +Contributed by Rishi*/ +#include +#include +#include +#include +#include +void time_clock() +{ + time_t currenttime; + time(¤ttime); + struct tm *ti=localtime(¤ttime); + + int i=1; + start: + if(i!=1) + system("cls"); + printf("%02d : %02d : ",ti->tm_hour,ti->tm_min); + + while(1) + { + + printf("%02d\b\b",ti->tm_sec); + + ti->tm_sec++; + if(ti->tm_sec==60) + { + ti->tm_sec=0; + goto min; + } + sleep(1); + i++; + } + min: + ti->tm_min++; + if(ti->tm_min==60) + { + goto hour; + } + goto start; + hour: + ti->tm_hour++;ti->tm_min=0; + if(ti->tm_hour==24) + { + ti->tm_hour=0; + ti->tm_min=0; + ti->tm_sec=0; + } + goto start; +} +int main() +{ +time_clock(); +}