blob: 4742b4672da7d3145ac156b4bbaa67dc42b88b87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<h1 id="firstHeading" class="firstHeading">ferror</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><stdio.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td class="t-dcl-nopad"> <pre data-language="c">int ferror( FILE *stream );</pre>
</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Checks the given stream for errors.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> stream </td> <td> - </td> <td> the file stream to check </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>Nonzero value if the file stream has errors occurred, <code>0</code> otherwise</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#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");
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">Error indicator set</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.21.10.3 The ferror function (p: 339) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.19.10.3 The ferror function (p: 305) </li></ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul><li> 4.9.10.3 The ferror function </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="clearerr" title="c/io/clearerr"> <span class="t-lines"><span>clearerr</span></span></a></div> </td> <td> clears errors <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="feof" title="c/io/feof"> <span class="t-lines"><span>feof</span></span></a></div> </td> <td> checks for the end-of-file <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/io/c/ferror" title="cpp/io/c/ferror">C++ documentation</a></span> for <code>ferror</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/io/ferror" class="_attribution-link">https://en.cppreference.com/w/c/io/ferror</a>
</p>
</div>
|