I am having a small problem with a countdown timer program.
I want it to countdown the time from say 01: 00 : 00 to 00 : 00 :00.
Here is the program.
Code:
#include <stdio.h>
#include <time.h>
#include <conio.h>
//A function for the seconds tick.
void wait( int sec )
{
clock_t end_wait;
end_wait = clock() + sec * CLK_TCK;
while (clock() < end_wait){}
}
int main(void)
{
int hours, seconds, s;
time_t t;
struct tm *tm;
tm = localtime(&t);
printf("Enter the number of seconds: ");
scanf("%d", &seconds);
s = seconds;
while(seconds > 0){
tm->tm_sec = s;
tm->tm_hour = s/3600;
tm->tm_min = s/60;
mktime(tm);
printf("%02d:%02d:%02d\n", tm->tm_hour, tm->tm_min, tm->tm_sec);
s--;
seconds--;
wait(1);
}
getch();
return 0;
}
The problem with the program is that it prints the time every time instead of just updating it like in a digital watch.
I want the program to print the time: for eg: 00 : 24: 30 and then after a second to print
00 : 24 :29.. but I want the new time to replace the old one and not print on a new line.
Any sort of help would be appreciated.
Regards,
Vijay