我想在每次循环运行时打印以打印文本,但我的程序只在最后一次循环运行时打印它.我的代码:
while (shots>i){
printf ("%s", message);
i++;
sleep(1);
}
Run Code Online (Sandbox Code Playgroud)
最后,我只是在一瞬间获得所有输出.
添加fflush(stdout);后printf从缓冲你的输出刷新到stdout.
输出不会stdout在缓冲区已满或者'\n'之类的特殊字符出现之前进行,您需要手动(通过调用fflush).