printf not printing to screen

前端 未结 3 564
有刺的猬
有刺的猬 2020-11-30 15:00

If I try to run the following simple code under Cygwin on Windows 7,

#include 
int main() {
int i1, i2, sums;

printf( \"Enter first integer         


        
相关标签:
3条回答
  • 2020-11-30 15:37

    you can try for disabling the buffering in stdout by using

    setbuf(stdout, NULL);
    
    0 讨论(0)
  • It seems that the output of your program is buffered. Try enabling line buffering explicitly:

    setlinebuf(stdout);
    
    0 讨论(0)
  • 2020-11-30 15:44

    Like @thejh said your stream seems to be buffered. Data is not yet written to the controlled sequence.

    Instead of fiddling with the buffer setting you could call fflush after each write to profit from the buffer and still enforce the desired behavior/display explicitly.

    printf( "Enter first integer\n" );
    fflush( stdout );
    scanf( "%d", &i1 );
    
    0 讨论(0)
提交回复
热议问题