開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
C
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
stdio.h
string.h
問題(Question):
實際測試和原本有出入
餵入的資料(Input):
預期的正確結果(Expected Output):
http://www.tutorialspoint.com/c_standard_library/c_function_setvbuf.htm
如這篇
錯誤結果(Wrong Output):
Going to set full buffering on
This is tutorialspoint.com
This output will g into buff
請按任意鍵繼續 . . .
少了兩行
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (int argc, char *argv[])
{
char buff[1024];
memset(buff, '\0', sizeof (buff));
fprintf (stdout, "Going to set full buffering on\n");
setvbuf (stdout, buff, _IOFBF, 1024);
fprintf (stdout, "This is tutorialspoint.com\n");
fprintf (stdout, "This output will g into buff\n");
fflush (stdout);
fprintf (stdout, "and this will appear when programm\n");
fprintf (stdout, "will come after sleeping 5 seconds\n");
sleep (5000);
system("PAUSE");
return 0;
}
補充說明(Supplement):
參閱這網站:http://blog.xuite.net/mb1016.flying/linux/28543400-fflush(stdout)
多少理解fflush的意思,可是我自己測試跟實際有點出入。
為什麼我fflush 之後就被截掉了? 我印象中他展示是沒有被截掉。
還有設定 setvbuf有何功用?