From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/io%2Fferror.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 devdocs/c/io%2Fferror.html (limited to 'devdocs/c/io%2Fferror.html') 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 @@ +

ferror

Defined in header <stdio.h>
int ferror( FILE *stream );
+

Checks the given stream for errors.

+

Parameters

+ +
stream - the file stream to check

Return value

Nonzero value if the file stream has errors occurred, ​0​ otherwise

+

Example

#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");
+}

Output:

+
Error indicator set

References

See also

+ + +
clears errors
(function)
checks for the end-of-file
(function)
C++ documentation for ferror
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/io/ferror +

+
-- cgit v1.2.3