fflush就是將output buffer的內容寫到file裡.那如果是fflush()就是寫到stdout.

Syntax:

#include <stdio.h>
int fflush( FILE *stream );

Description:
If the given file stream is an output stream, then fflush() causes the output buffer to be written to the file. If the given stream is of the input type, then fflush() causes the input buffer to be cleared. fflush() is useful when debugging, if a program segfaults before it has a chance to write output to the screen. Calling fflush( STDOUT ) directly after debugging output will ensure that your output is displayed at the correct time.

#include<stdio.h>
#include<unistd.h>

int main()
{
#if 1
        int i;
        for (i=0;i<10;i++)
        {
          printf("%d",i);
           fflush(stdout);
          sleep(1);
        }
#endif
        return 0;
}

如果有加fflush就會每執行一個for 回圈就印一次.如果沒有的話就會到跳出for迴圈後才印.

 

 

Description

The function fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function. The open status of the stream is unaffected.

If the stream argument is NULL, fflush() flushes all open output streams.

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 horace papa 的頭像
    horace papa

    Horace papa's life

    horace papa 發表在 痞客邦 留言(0) 人氣()