...
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stddef.h>
#include <stdio.h>
#include <wchar.h>
enum {BUFFER_SIZE = 32 }
void g(void) {
wchar_t buf[BUFFER_SIZE];
wint_t wc;
size_t i = 0;
while ((wc = getwc(stdin)) != L'\n' && wc != WEOF) {
if (i < BUFFER_SIZE - 1) {
buf[i++] = wc;
}
}
if (feof(stdin) || ferror(stdin)) {
buf[i] = L'\0';
} else {
/* Received a wide character that resembles WEOF; handle error */
}
}
|
Exceptions
FIO34-C-EX1: A number of C functions do not return characters but can return EOF as a status code. These functions include fclose(), fflush(), fputs(), fscanf(), puts(), scanf(), sscanf(), vfscanf(), and vscanf(). These return values can be compared to EOF without validating the result.
...