C examples for wchar.h:getwc
function
<cwchar> <wchar.h>
Get wide character from stream
wint_t getwc (FILE* stream);
Parameter | Description |
---|---|
stream | Pointer to a FILE object. |
On success, the character read is returned.
On error, WEOF is returned, which indicates failure.
#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; }