ferror
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <stdio.h> で定義
|
||
int ferror( FILE *stream ); |
||
指定されたストリームのエラーを調べます。
引数
| stream | - | 調べるファイルストリーム |
戻り値
ファイルストリームにエラーが発生した場合は非ゼロの値、そうでなければ 0。
例
Run this code
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
int main(void)
{
char* fname = tmpnam(NULL);
FILE* f = fopen(fname, "wb");
fputs("\xff\xff\n", f); // not a valid UTF-8 character sequence
fclose(f);
setlocale(LC_ALL, "en_US.utf8");
f = fopen(fname, "rb");
wint_t ch;
while ((ch=fgetwc(f)) != WEOF) // attempt to read as UTF-8 fails
printf("%#x ", ch);
if (feof(f))
puts("EOF indicator set");
if (ferror(f))
puts("Error indicator set");
}
出力:
Error indicator set