Why does my output only print if there is another print after it?

后端 未结 3 869
[愿得一人]
[愿得一人] 2020-12-22 01:57

Interesting little bug here:

if (host != NULL) {
    printf("hi");
} else {
    printf("FAIL");
}
return 0;

doesn\'t prin

相关标签:
3条回答
  • printf output to stdout is buffered. You might want to look at fflush

    0 讨论(0)
  • 2020-12-22 02:09

    The difference is the \n characters.

    As you printf characters, they are accumulated in a buffer which isn't sent to the output device until an 'end of line' character is sent.

    0 讨论(0)
  • 2020-12-22 02:20

    try using fflush(stdout) before your if condition.

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