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

get_char(+Stream, -Char)

Reads the next character from the input stream Stream
Stream
Stream handle or alias (atom)
Char
Single character string or variable.

Description

Takes a single character string from the input stream Stream. and unifies it with Char.

Note that this predicate returns a string, while the corresponding predicate iso:get_char/2 returns an atom!

Modes and Determinism

Exceptions

(4) instantiation fault
Stream is not instantiated.
(5) type error
Stream is neither a stream handle nor an atom.
(5) type error
Char is instantiated, but not to a single character string.
(190) end of file reached
End of file has been reached.
(192) illegal stream mode
Stream is not open for reading.
(193) illegal stream specification
Stream is not a valid stream number.

Examples

   Success:
      ?- get_char(input,Char).
       a
      Char = "a"
      yes.

      ?- get_char(input, "b").
       b
      yes.

      ?- sh('cat file1').
      p
      yes.
      ?- open(file1, update,s),
         get_char(s,X).
      X = "p"
      yes.
Fail:
      ?- get_char(input, "b").
       a
      no.

Error:
      get_char(Stream, "b").             (Error 4).
      get_char(input, 'b').              (Error 5).
      get_char(input, 98.0).             (Error 5).
      get_char("string", Char).          (Error 5).
      get_char(null,Char).              (Error 190).
      get_char(9,Char).                 (Error 192).
      get_char(atom,Char).              (Error 193).



See Also

get / 1, get / 2, get_char / 1, iso : get_char / 2, put / 1, put / 2, put_char / 1, put_char / 2