getwc - C wchar.h

C examples for wchar.h:getwc

Type

function

From


<cwchar>
<wchar.h>

Description

Get wide character from stream

Prototype

wint_t getwc (FILE* stream);

Parameters

Parameter Description
stream Pointer to a FILE object.

Return Value

On success, the character read is returned.

On error, WEOF is returned, which indicates failure.

Demo Code

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

int main ()//w  ww .  jav a  2 s  .  co  m
{
  FILE * pFile;
  wint_t wc;
  int n = 0;
  pFile=fopen ("main.cpp","r");

  if (pFile!=NULL){
    perror("cannot open file");
    return -1;
  }
  do {
      wc = getwc (pFile);
      if (wc == L'$') n++;
  } while (wc != WEOF);
  fclose (pFile);
  wprintf (L"The file contains %d dollar sign characters ($).\n",n);

  return 0;
}

Related Tutorials