Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fseek(3)

getc(3)

setbuf(3)

stdio(3)



  ungetc(3)                           CLIX                           ungetc(3)



  NAME

    ungetc - Pushes a character back into input stream

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <stdio.h>

    int ungetc(
      int c ,
      FILE *stream );

  PARAMETERS

    c        Specifies a character.

    stream   Points to a stream.

  DESCRIPTION

    The ungetc() function inserts the character c into the buffer associated
    with an input stream.  That character, c, will be returned by the next
    getc() call on that stream.  The ungetc() function returns c, and leaves
    the file stream unchanged.

    One character of pushback is guaranteed, provided something has already
    been read from the stream and the stream is actually buffered.

    If c equals EOF, ungetc does nothing to the buffer and returns EOF.

    The fseek() function erases all memory of inserted characters.

    When stream is stdin, one character may be pushed back onto the buffer
    without a previous read statement.

  EXAMPLES

    To strip all of the comments out of a file:

    #include <stdio.h>

    blast_comment()
    {
         char first_character, second_character;

         for(;;;)
              if ((first_character = getc(infile)) == '*')



  2/94 - Intergraph Corporation                                              1






  ungetc(3)                           CLIX                           ungetc(3)



                   if((second_character = getc(infile)) == '*')
                        ungetc(second_character, infile);
                   else if (second_character == '/')
                        return;
    }


  RETURN VALUES

    The ungetc() function returns EOF if it cannot insert the character.

  RELATED INFORMATION

    Functions:  fseek(3), getc(3), setbuf(3), stdio(3)








































  2                                              Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026