This shows you the differences between two versions of the page.
c:wchar.h:fgetwc [2013/01/22 22:02] |
c:wchar.h:fgetwc [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ===== fgetwc ===== | ||
+ | <code c> | ||
+ | #include <wchar.h> | ||
+ | wint_t fgetwc(FILE *); | ||
+ | </code> | ||
+ | |||
+ | ==== fgetwc Description ==== | ||
+ | fgetwc reads in a single character from Stream and returns its value as a wide character. | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * fgetwc example code | ||
+ | * http://code-reference.com/c/wchar.h/fgetwc | ||
+ | */ | ||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | #include <wchar.h> | ||
+ | |||
+ | int main( void ) | ||
+ | { | ||
+ | FILE* stream = fopen("testmb.txt", "r"); | ||
+ | |||
+ | if (!stream) { | ||
+ | printf("Could not open the file\n"); | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | wchar_t wchar = fgetwc(stream); | ||
+ | if (wchar != WEOF) { | ||
+ | printf("char read: %c\n", wchar); | ||
+ | } else { | ||
+ | printf("read error\n"); | ||
+ | } | ||
+ | fclose(stream); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | === content of testmb.txt === | ||
+ | <file txt testmb.txt> | ||
+ | A | ||
+ | B | ||
+ | C | ||
+ | </file> | ||
+ | |||
+ | ==== output ==== | ||
+ | |||
+ | A | ||
+ | |||
+ | |||
+ | |||
+ |