?
? ????? PHP ??? ???? ??? ?? ??
在頭文件<stdio.h>中定義 | ||
---|---|---|
int ferror(FILE * stream); |
檢查給定的流是否有錯(cuò)誤。
流 | - | 要檢查的文件流 |
---|
非零值,如果文件流發(fā)生錯(cuò)誤,0
否則。
#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
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.21.10.3恐怖功能(p:339)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.19.10.3恐怖功能(p:305)
C89 / C90標(biāo)準(zhǔn)(ISO / IEC 9899:1990):
4.9.10.3恐怖功能