C examples for wchar.h:ungetwc
function
<cwchar> <wchar.h>
Unget wide character from stream
wint_t ungetwc (wint_t wc, FILE* stream);
Parameter | Description |
---|---|
wc | character to be put back. |
stream | Pointer to a FILE object |
On success, the wide character put back is returned.
If the operation fails, WEOF is returned.
#include <stdio.h> #include <wchar.h> int main ()/*w w w . jav a 2s . c o m*/ { FILE * pFile; wint_t wc; wchar_t buffer [256]; pFile = fopen ("main.cpp","rt"); if (pFile==NULL) { perror("cannot open file"); return -1; } while (!feof (pFile)) { wc=getwc (pFile); if (wc != WEOF) { if (wc == L'#') ungetwc (L'@',pFile); else ungetwc (wc,pFile); fgetws (buffer,255,pFile); fputws (buffer,stdout); } } return 0; }