I want to turn off the buffering for the stdout for getting the exact result for the following code
我想关闭stdout的缓冲,以获得以下代码的确切结果
while(1) {
printf(".");
sleep(1);
}
The code printf bunch of '.' only when buffer gets filled.
代码printf一堆'。'只有当缓冲区被填满时
5 个解决方案
#1
4
Use fflush(stdout)
. You can call it after every printf
to force the buffer to flush.
使用fflush(标准输出)。您可以在每个printf之后调用它来强制缓冲区刷新。
#3
7
You can also use setbuf
您也可以使用setbuf
setbuf(stdout, NULL);
This will take care of everything
这将照顾一切
#4
0
Use fflush(FILE *stream) with stdout as the parameter.
使用fflush(FILE * stream)和stdout作为参数。
http://www.elook.org/programming/c/fflush.html
http://www.elook.org/programming/c/fflush.html
#5
-2
You can do
你可以做
write(1, ".", 1);
instead of
代替
printf(".");
#1
4
Use fflush(stdout)
. You can call it after every printf
to force the buffer to flush.
使用fflush(标准输出)。您可以在每个printf之后调用它来强制缓冲区刷新。
#2
#3
7
You can also use setbuf
您也可以使用setbuf
setbuf(stdout, NULL);
This will take care of everything
这将照顾一切
#4
0
Use fflush(FILE *stream) with stdout as the parameter.
使用fflush(FILE * stream)和stdout作为参数。
http://www.elook.org/programming/c/fflush.html
http://www.elook.org/programming/c/fflush.html
#5
-2
You can do
你可以做
write(1, ".", 1);
instead of
代替
printf(".");