|  #include <stdio.h> | 
|  #include <wchar.h> | 
| wint_t
               
               
               ungetwc (wint_t wc, FILE *stream); | 
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.
#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);
}
         
      
| © 2005-2007 Nokia |