6.23.7 fgetwc Function

Obtains wide character input from a stream.

Attention: This function is implemented only by MPLAB XC32 C compilers.

Include

<wchar.h>

Prototype

int fgetwc(FILE * stream);

Arguments

stream
the stream to read input from

Return Value

Returns the next available wide character as a wchar_t converted to a wint_t. The WEOF wide character is returned if the end-of-file indicator for the stream is set, if the stream is at end-of-file, if a read error occurs, or if an encoding error occurs.

Remarks

This function advances the associated file position indicator for the stream (if defined) and sets the end-of file indicator when the end-of-file is reached. If a read error occurs, the error indicator for the stream is set and can be checked with the ferror() function. If an encoding error occurs (which includes too few bytes), errno is set to the value of the EILSEQ macro.

Example

#include <wchar.h>
#include <stdio.h>

int main(void)
{
  FILE * myfile;
  wint_t wc;

  if ((myfile = fopen("afile", "r")) == NULL)
    wprintf(L"Cannot open afile\n");
  else
  {
    while( ! feof(myfile)) {
      wc = fgetwc(myfile);
      if(iswprint(wc))
        wprintf(L"char read: %lc\n", wc);
    }
    fclose(myfile);
  }
}

Example Input

Content of afile.

Four score

Example Output

char read: F
char read: o
char read: u
char read: r
char read:  
char read: s
char read: c
char read: o
char read: r
char read: e