开发者

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

开发者 https://www.devze.com 2022-12-19 00:14 出处:网络
Interesting little bug here: if (host != NULL) { printf("hi"); } else { printf("FAIL");

Interesting little bug here:

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

doesn't print anything at all, but:

if (host != NULL) {
    printf("hi"开发者_如何学编程;);
} else {
    printf("FAIL");
}   
fprintf(stdout, "\n%s\n", (char *)&additionalargs);
return 0;

prints

hi

abc

Does anyone know why this is?


printf output to stdout is buffered. You might want to look at fflush


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.


try using fflush(stdout) before your if condition.

0

精彩评论

暂无评论...
验证码 换一张
取 消