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:
- Explicitly flush the buffer by calling
fflush( stdout )
every time you useprintf
- Disable buffering
setbuf(stdout, NULL);
- Flush buffer by using newline
\n
at end ofprintf
string Ex:printf("n= \n");
Your code worked in some environments probably because buffering is disabled there.