diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/io%2Fferror.html | |
new repository
Diffstat (limited to 'devdocs/c/io%2Fferror.html')
| -rw-r--r-- | devdocs/c/io%2Fferror.html | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/devdocs/c/io%2Fferror.html b/devdocs/c/io%2Fferror.html new file mode 100644 index 00000000..4742b467 --- /dev/null +++ b/devdocs/c/io%2Fferror.html @@ -0,0 +1,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> |
