printf not print on the console in eclipse?

printf doesn’t print to screen unless buffer is flushed

Looks like your streams are buffered. Data you write to stdout and other streams is buffered and all output once you flush your buffer. This allows for better performance as IO is slowest among all your CPU operations.

At this point, you have at least these options:

  1. Explicitly flush the buffer by calling fflush( stdout ) every time you use printf
  2. Disable buffering setbuf(stdout, NULL);
  3. Flush buffer by using newline \n at end of printf string Ex: printf("n= \n");

Your code worked in some environments probably because buffering is disabled there.

Leave a Comment