Why fprintf doesn't write directly into the file unless fflush() is used?

前端 未结 3 408
北海茫月
北海茫月 2020-12-22 08:27

I have written a daemon that writes a value in a file. What I have observed is that when I keep writing on a file, there is nothing visible in the file. in other hand, If I

3条回答
  •  隐瞒了意图╮
    2020-12-22 09:25

    By default, stdio is fully buffered, unless it's writing to a terminal, in which case it's line-buffered, or stderr, which is not buffered at all.

    You can disable buffering with the setbuf() function.

    setbuf(fp, NULL);
    

提交回复
热议问题