Following is my code : -
#include <stdio.h>
#include <unistd.h>
int main()
{
int i;
printf("Continue in...");
for (i = 10; i > 0 ; --i)
{
printf("%d",i);
sleep(1);
printf("\b");
}
}
I am trying to make a countdown timer in C, so that only the value of i changes on the STDOUT, and the words "Continue in..." stay as it is on the shell(i.e at the same location of screen).
But the code above produces nothing for 10 seconds, rather just prints the string "Continue in..." after 10th second.
I read this answer which says that the behaviour of \b is terminal dependent. My question is what should I edit in my code to make its output independent from the output device.