Why does “printf” not produce any output?

后端 未结 2 1178
借酒劲吻你
借酒劲吻你 2020-12-17 16:05

I am learning to program in C. Could you explain why nothing is printed here?

#include 

int main (void)
{
    char a[]="abcd         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 16:51

    Doing a fflush() could be expensive if you also have other streams other than stdout open for write, like say a file outputting to disk. Running fflush() will flush all streams not just stdout. It would be better to be more specific and pass the stream to flush. So for printf() which outputs to stdout you'd use fflush(stdout). A alternative if you're looking to output errors would be to use stderr as that's unbuffered with fprintf().

    Also you can use setvbuf to change an open streams buffer before writing to it. See man setvbuf

提交回复
热议问题