开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜