我有一个简单的代码”
int格式的printInterval
sleep(printinterval/3);
displayPrint(); //// just some printing func
sleep(printinterval/3);
displayPrint();
sleep(printinterval-2*(int)(printinterval/3));
displayPrint();
问题是它没有以正确的方式延迟,
一觉醒来
但是
sleep(printinterval/3);
printf("\n");
displayPrint(); //// just some printing func
printf("\n");
sleep(printinterval/3);
printf("\n");
displayPrint();
printf("\n");
sleep(printinterval-2*(int)(printinterval/3));
printf("\n");
displayPrint();
像个符咒
有什么想法吗?
泰铢:)
编辑:
谢谢你的帮助
找到了这个方法来修复它
fflush(stdout); // Will now print everything in the stdout buffer
再说一遍,thx
最佳答案
流被缓冲,并在遇到\n
时刷新。
见:Why does printf not flush after the call unless a newline is in the format string?