why doesn't this c programme print the first printf statement?

前端 未结 3 1106
生来不讨喜
生来不讨喜 2020-12-15 12:39
#include
#include 
int main(){
      while(1)
      {

              fprintf(stdout,\"hello-out\");
              fprintf(stderr,\"hel         


        
3条回答
  •  情歌与酒
    2020-12-15 13:10

    If you add a '\n' to your message it will (or should), ie. "hello-out\n".

    The reason being is that stdout is buffered in order to be more efficient, whereas stderr doesn't buffer it's output and is more appropriate for error messages and things that need to be printed immediately.

    stdout will usually be flushed when:

    • A newline (\n) is to be printed
    • You read in from stdin
    • fflush() is called on it

    EDIT: The other thing I wanted to add before my computer crashed...twice...was that you can also use setbuf(stdout, NULL); to disable buffering of stdout. I've done that before when I've had to use write() (Unix) and didn't want my output to be buffered.

提交回复
热议问题