I was trying to use the '\r' character to write over the previous line; however, when used in conjunction with nanosleep(), the program does not output until the end. Here is a code example:
int i;
struct timespec t = {1, 0};
for (i = 0; i < 10; ++i) {
nanosleep(&t, NULL);
printf('\ri: %d', i);
}
This will wait for 10 seconds, and then print out i: 9
. I would like it to show the updates, not just the end. I'm not sure if the line is being flushed or something?
Any and all help is greatly appreciated!