Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    int ungetc( int c, FILE *fp );
    #include <stdio.h>
    #include <wchar.h>
    wint_t ungetwc( wint_t c, FILE *fp );

Description:
    The ungetc function pushes the character specified by c back onto the
    input stream pointed to by fp.  This character will be returned by the
    next read on the stream.  The pushed-back character will be discarded if
    a call is made to the  fflush function or to a file positioning function
    ( fseek,  fsetpos or  rewind) before the next read operation is
    performed.

    Only one character (the most recent one) of pushback is remembered.

    The ungetc function clears the end-of-file indicator, unless the value
    of c is  EOF.

    The ungetwc function is identical to ungetc except that it pushes the
    wide character specified by c back onto the input stream pointed to by
    fp.

    The ungetwc function clears the end-of-file indicator, unless the value
    of c is  WEOF.

Returns:
    The ungetc function returns the character pushed back.

Example:
    #include <stdio.h>
    #include <ctype.h>

    void main()
      {
        FILE *fp;
        int c;
        long value;

        fp = fopen( "file", "r" );
        value = 0;
        c = fgetc( fp );
        while( isdigit(c) ) {
            value = value*10 + c - '0';
            c = fgetc( fp );
        }
        ungetc( c, fp ); /* put last character back */
        printf( "Value=%ld\n", value );
        fclose( fp );
      }

Classification:
    ungetc is ANSI, ungetwc is ANSI

Systems:
     ungetc - All, Netware

    ungetwc - All

See Also:
    fgetc, fgetchar, fgets, fopen, getc, getchar, gets

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson