Table of Contents

fgetwc

   #include <wchar.h>
   wint_t fgetwc(FILE *);

fgetwc Description

fgetwc reads in a single character from Stream and returns its value as a wide character.

C Sourcecode Example

/* 
 * 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;
}

content of testmb.txt

testmb.txt
A
B
C

output

  A