ferrorferror

测试流中的错误。Tests for an error on a stream.

语法Syntax

int ferror(
   FILE *stream
);

参数Parameters

stream
指向文件结构的指针。Pointer to FILE structure.

返回值Return Value

如果不发生任何错误ferror返回 0。If no error has occurred on stream, ferror returns 0. 否则,返回一个非零值。Otherwise, it returns a nonzero value. 如果流是NULLferror中所述调用无效参数处理程序,参数验证If stream is NULL, ferror invokes the invalid parameter handler, as described in Parameter Validation. 如果允许执行继续,此函数将errnoEINVAL并返回 0。If execution is allowed to continue, this function sets errno to EINVAL and returns 0.

有关这些代码以及其他错误代码的详细信息,请参阅 _doserrno、errno、_sys_errlist 和 _sys_nerrSee _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, error codes.

备注Remarks

Ferror的读取或写入错误,与关联的文件的例程 (同时作为函数和宏实现) 测试The ferror routine (implemented both as a function and as a macro) tests for a reading or writing error on the file associated with stream. 如果出现错误,直到流已关闭或回退,或直到将保持设置为流的错误指示器clearerr针对其调用。If an error has occurred, the error indicator for the stream remains set until the stream is closed or rewound, or until clearerr is called against it.

要求Requirements

函数Function 必需的标头Required header
ferrorferror <stdio.h><stdio.h>

有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

请参阅 feof 的示例。See the example for feof.

请参阅See also

错误处理Error Handling
流 I/OStream I/O
clearerrclearerr
_eof_eof
feoffeof
fopen、_wfopen_wfopenfopen, _wfopen
perror、_wperrorperror, _wperror