fflush
stdio.h:インデックス への移動
ヘッダーファイル
stdio.h
カテゴリ
入出力ルーチン
プロトタイプ
int fflush(FILE *stream);
説明
ストリームをフラッシュします。
指定されたストリームが出力をバッファリングしている場合,fflush は,ストリームの出力を関連するファイルに書き込みます。
fflush の実行後もストリームは開いたままです。fflush は,バッファリングされないストリームには効果がありません。
戻り値
成功した場合,fflush は 0 を返します。エラーが検出された場合は,EOF を返します。
例
#include <string.h>
#include <stdio.h>
#include <io.h>
void flush(FILE *stream);
int main(void)
{
FILE *stream;
char msg[] = "This is a test";
/* ファイルを作成します */
stream = fopen("DUMMY.FIL", "w");
/* ファイルにデータを書き込みます */
fwrite(msg, strlen(msg), 1, stream);
printf("Press ENTER to flush DUMMY.FIL:");
getchar();
/* データを DUMMY.FIL にフラッシュし,ファイルは閉じません */
flush(stream);
printf("\nFile was flushed, Press ENTER to quit:");
getchar();
return 0;
}
void flush(FILE *stream)
{
int duphandle;
/* ストリームの内部バッファをフラッシュします */
fflush(stream);
/* 複製ファイルハンドルを作成します */
duphandle = dup(fileno(stream));
/* 複製ハンドルを閉じて DOS バッファをフラッシュします */
close(duphandle);
}
移植性
POSIX | Win32 | ANSI C | ANSI C++ |
---|---|---|---|
+ |
+ |
+ |
+ |