Why is C printing outputs late?

前端 未结 1 568
無奈伤痛
無奈伤痛 2021-01-22 12:29

I am currently running a piece of C code on my Raspberry Pi computer. It is a random number generator that reads from a Geiger counter connected to GPIO digital input 18. It mak

相关标签:
1条回答
  • 2021-01-22 12:52

    By default, output on stdout is line-buffered when it's writing to a terminal. This means that the output will be held in memory until you print a newline or call fflush(stdout) (or the output buffer fills up -- that's typically 4K or 8K characters).

    So put fflush(stdout) at the places where you want the accumulated output to be displayed. Or use setbuf(stdout, NULL) to disable buffering entirely.

    0 讨论(0)
提交回复
热议问题