6.23.14 getwc Function

Obtains wide character input from a stream.

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

Include

<wchar.h>

Prototype

int getwc(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

The getwc() function is equivalent to fgetwc().

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 = getwc(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