Search code examples
raspbiancarriage-return

Command line doesn't refresh immidately after carriage return


I have a code which does something similar to this one.

while(1){
      printf("Telegrams received %d\r",telegrams); //notice \r
      telegrams++;
      sleep(); // for 0.2s
}

The output from this is one line in a command line which is being updated. However my problem is, that the line isn't updated after every telegram, but only after every 17... (which takes something like 3 seconds). Is there any way, how to make this work to change every 0.2 seconds? (when I press enter, there is displayed everything...)

I'm running this on raspberry pi with raspbian.

Thanks


Solution

  • Found an answer - I need to use fflush(stdout) after every printf.