[ Character I/O | Reference Manual | Alphabetic Index ]

# get(+Stream, -Code)

Reads the next character from the input stream Stream

Stream
  Stream handle or alias (atom)
Code
  Variable or integer.

## Description

Takes the next character from the input stream Stream, and unifies its integer character code with Code. The range of possible values depends on the stream's text encoding, or is 0 to 255 for binary streams.

Character codes for the non-printable characters (i.e. control characters) are treated like normal characters.

On end-of-file, -1 is returned (via the default handler for event 190).

### Modes and Determinism

- get(+, -) is det

### Exceptions

(4) instantiation fault
  Stream is not instantiated.
(5) type error
  Stream is neither a stream handle nor an atom.
(5) type error
  Code is instantiated, but not to an integer.
(190) end of file reached
  End of file has been reached.
(192) illegal stream mode
  Stream is not an input stream.
(193) illegal stream specification
  Stream is an illegal stream specification.

## Examples

    Success:
          ?- get(input, X).
           a
          X = 97
          yes.

          ?- get(input, 0'a), get(input,97).
           aa
          yes.
    Fail:
          ?- get(input,98).
           a
          no.
    Error:
          get(Stream,98).                 (Error 4).
          get(input, '98').               (Error 5).
          get(10,A).                      (Error 192).
          get(atom,A).                    (Error 193).

## See Also

get / 1, put / 1, put / 2