unread_char

Gamma: Version 4.0
Prev |  | Next

# `unread_char`

`unread_char` -- attempts to replace a character to a file for subsequent reading.

## Syntax

    unread_char (file, character)

## Arguments

`file`

  A file pointer to a previously opened file. This may be either a file in the file system, or a string opened for read and write.

`character`

  A single character.

## Returns

t if the `character` could be replaced on the `file`, otherwise nil.

## Description

This function attempts to place the given `character` back onto the `file` so that it can be read again by subsequent calls to any of the `read` family of functions. Only one character may be replaced onto a file between calls to `read`. At least one `read` call must have been made prior to calling this function.

## Example

An input file contains the following:

              ABCDE

A call to `unread_char` within a succession of calls to `read_char` will produce:

        Gamma> fr = open("myunreadfile.dat", "r", t);
        #<File:"myunreadfile.dat">
        Gamma> read_char(fr);
        65
        Gamma> read_char(fr);
        66
        Gamma> unread_char(fr,'A');
        t
        Gamma> read_char(fr);
        65
        Gamma> read_char(fr);
        67
        Gamma> read_char(fr);
        68
        Gamma>

## See Also

`read`

Prev | Home | Next
`terpri` | Up | `write`, `writec`, `pretty_write`, `pretty_writec`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.