The code I wrote for a digital clock always falls behind the clock in my windows 7 taskbar after being run for like 2-3 mins. Why?
Here's the code:
#include <stdio.h>
#include <time.h>
#include <windows.h>
int main()
{
int h,m,s;
time_t epoch_time;
struct tm *tm_p;
epoch_time = time( NULL );
tm_p = localtime( &epoch_time );
h=tm_p->tm_hour%12;
m=tm_p->tm_min;
s=tm_p->tm_sec;
while(1)
{
if(s>59)
{
m=m+1;
s=0;
}
if(m>59)
{
h=h+1;
m=0;
}
if(h>11)
{
h=0;
m=0;
s=0;
}
Sleep(1000);
s++; // trying something I learned (s=s+1)
system ("cls");
printf(" %d:%d:%d",h,m,s);
}
}