[問題] 有關於 fflush 和 setvbuf
開發平台(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有何功用?
--
志願役普遍垃圾不代表每個志願役都是垃圾。
苗栗人智商普遍低落,不代表每個苗栗人智商都很低。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.30.118
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1454566330.A.006.html
推
02/04 17:15, , 1F
02/04 17:15, 1F
→
02/04 17:16, , 2F
02/04 17:16, 2F
→
02/04 17:17, , 3F
02/04 17:17, 3F
→
02/04 18:05, , 4F
02/04 18:05, 4F
推
02/04 18:10, , 5F
02/04 18:10, 5F
→
02/04 18:11, , 6F
02/04 18:11, 6F
推
02/06 15:52, , 7F
02/06 15:52, 7F
→
02/06 23:04, , 8F
02/06 23:04, 8F
→
02/06 23:19, , 9F
02/06 23:19, 9F