Name

ungetwc - push back a wide character onto a FILE stream

Library

libc.lib

Synopsis

  #include <stdio.h>
  #include <wchar.h>
  wint_t ungetwc (wint_t wc, FILE *stream);

Return values

The ungetwc function returns the wide character pushed-back after the conversion, or WEOF if the operation fails. If the value of the argument c character equals WEOF, the operation will fail and the stream will remain unchanged.

Detailed description

The ungetwc function pushes the wide character wc (converted to an wchar_t ) back onto the input stream pointed to by stream. The pushed-backed wide characters will be returned by subsequent reads on the stream (in reverse order). A successful intervening call, using the same stream, to one of the file positioning functions fseek, fsetpos, or rewind will discard the pushed back wide characters.

One wide character of push-back is guaranteed, but as long as there is sufficient memory, an effectively infinite amount of pushback is allowed.

If a character is successfully pushed-back, the end-of-file indicator for the stream is cleared.


Examples

#include <stdio.h>
#include <wchar.h>
/* Illustrates how to use ungetwc API */
wint_t example_ungetwc(void)
{
 FILE *fp = NULL;
 wint_t wc1;
 wint_t rval;
 wint_t wc2;
 /* opening the file to write*/
 fp = fopen("input.txt","w");
 if(fp == NULL)
 {
  wprintf(L"Error: File open\n");
  return (-1);
 }
 /* character to written back to the fp */
 wc = (wint_t) L’e’;
 /* write the character into the fp */
 rval = ungetwc(wc, fp);
 /* check for error */
 if(rval == WEOF)
 {
        wprintf(L"ungetwc returned error!!\n");
 }
 /* Read the character from fp */
 /* this char should be the same as the char */
 /* that was written by ungetwc */
 wc2 = getwc(fp);
 /* Close the file opened for writing */
 fclose(fp);
 /* return the value that was written */
 return (rval);
}

         


See also

fseek, getwc

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top