| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <wchar.h> | ||
wint_t fgetwc(FILE*stream); | (since C95) | |
wint_t getwc(FILE*stream); | (since C95) | |
Reads the next wide character from the given input stream.getwc() may be implemented as a macro and may evaluatestream more than once.
Contents |
| stream | - | to read the wide character from |
The next wide character from the stream orWEOF on failure.
If the failure has been caused by end-of-file condition, additionally sets theeof indicator (seefeof()) onstream. If the failure has been caused by some other error, sets theerror indicator (seeferror()) onstream.
If an encoding error occurred, additionally setserrno toEILSEQ.
#include <stdio.h>#include <stdlib.h>#include <wchar.h>#include <errno.h>#include <locale.h> int main(void){setlocale(LC_ALL,"en_US.utf8");FILE*fp=fopen("fgetwc.dat","w");if(!fp){perror("Can't open file for writing");returnEXIT_FAILURE;}fputs("кошка\n", fp);fclose(fp); fp=fopen("fgetwc.dat","r");if(!fp){perror("Can't open file for reading");returnEXIT_FAILURE;} wint_t wc;errno=0;while((wc= fgetwc(fp))!= WEOF)putwchar(wc); if(ferror(fp)){if(errno==EILSEQ)puts("Character encoding error while reading.");elseputs("I/O error when reading");}elseif(feof(fp))puts("End of file reached successfully"); fclose(fp);}
Output:
кошка
| gets a character from a file stream (function)[edit] | |
(C95) | gets a wide string from a file stream (function)[edit] |
(C95) | writes a wide character to a file stream (function)[edit] |
(C95) | puts a wide character back into a file stream (function)[edit] |
C++ documentation forfgetwc | |