int main(){ while(1){ printf("."); sleep(1); } return 0; }
while(1){ printf("."); fflush(stdout); sleep(1); }
在用 printf debug 大法時要注意這個問題 XD
我記得fflush用在stdout會有啥問題的樣子我查到另一個辦法是直接改stdout setvbuf(stdout, NULL, _IONBF, 0);
http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin
糗大....我看反了,是不應該fflush(stdin) /facepalm
在用 printf debug 大法時要注意這個問題 XD
回覆刪除我記得fflush用在stdout會有啥問題的樣子
回覆刪除我查到另一個辦法是直接改stdout
setvbuf(stdout, NULL, _IONBF, 0);
http://stackoverflow.com/questions/1716296/why-does-printf-not-flush-after-the-call-unless-a-newline-is-in-the-format-strin
回覆刪除糗大....我看反了,是不應該fflush(stdin) /facepalm
回覆刪除