Why, in this program, does the printf
function print or not print depending on where it is inside the loop?
#include <stdio.h>
#include <time.h>
int main()
{
char frames[] = {'-', '\', '|', '/'};
int i = 0;
time_t prev_time = time(0);
while(1) {
printf("r%c", frames[i % 4]); //<- when placed here, it will flush
if (time(0) - prev_time < 1) continue;
//printf("r%c", frames[i % 4]); <- when placed here, it needs to be manually flushed
//fflush(stdout);
prev_time = time(0);
i++;
}
return 0;
}