-
replacing console output
i want to display a timer in C with sleep function,but the problem is that I want to display the remaining time and then overwrite it after 1 second.How can i overwrite a number that i have already
dsplayed it on the console and then replace it with another diget?
I am working in gcc.
-
hmm
but when it go to single digit, the units digit is replaced with 0 and the actual unit digit shifts to tens position.like to go from 10 to 9, it turns into 90!
-
Hi, I am new to the board :)
Anyway, you could always do a check for timer. If it's < 10 you print 0%d (that's a zero). If it's > 10, you print %d...
Code:
'
do {
if (timer < 10) {
printf( "\r0%d", timer );
} else {
printf( "\r%d", timer );
}
'
-
Or you could do it the easy way:
>>printf ("%02d\n", 1);
The 02 means a minimum field width of 2, filled with leading zeros.