ungetc()                 Push Character Back onto the Stream
 
 #include   <stdio.h>
 
 int        ungetc(c,stream);
 int        c;                           Character to be pushed
 FILE       *stream;                     Pointer to file structure
 
    ungetc() pushes 'c' back onto the named input 'stream'. 'stream' must
    be buffered and open for reading.  The next call after ungetc() to
    getc() or fread() returns 'c'.  An attempt to push EOF is ignored.
 
    Returns:    The character argument 'c' is returned, if successful.
                EOF indicates a failure to push back 'c', or an attempt
                to push back a character before any have been read.
 
      Notes:    fseek() or rewind() may erase a pushed-back character if
                either is called before the character is reread.
 
  -------------------------------- Example ---------------------------------
 
    The following statements open a file, read characters, and push back
    the last character read.
 
         #include <stdio.h>
 
         FILE *stream;
         int i, ch;
 
         main()
         {
             if ((stream = fopen("msg.txt","r+")) != NULL) {
                i = 0;
                while ((ch = getc(stream)) != '@')
                      buffr[i++] = ch;
                ungetc(ch);
                fclose(stream);
             }
         }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster