printf not print on the console in eclipse?

前端 未结 1 1630
轮回少年
轮回少年 2021-01-03 16:36
#include

int main() {
    int n, s, i;
    do {
        printf(\"n= \"); // here is the problem ?
        scanf(\"%d\", &n);
    } while (n<10         


        
1条回答
  •  孤城傲影
    2021-01-03 16:49

    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.

    0 讨论(0)
提交回复
热议问题