ungetwc - C wchar.h

C examples for wchar.h:ungetwc

Type

function

From


<cwchar>
<wchar.h>

Description

Unget wide character from stream

Prototype

wint_t ungetwc (wint_t wc, FILE* stream);

Parameters

Parameter Description
wc character to be put back.
stream Pointer to a FILE object

Return Value

On success, the wide character put back is returned.

If the operation fails, WEOF is returned.

Demo Code

#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;
}

Related Tutorials