get_char(@stream_or_alias, ?in_character) [ISO]

This built-in clause reads a single character from the stream, the stream is altered. The input stream must be a text stream that was opened for reading. If Char is a variable or an in_character (a character or the atom 'end_of_file') then:

see also: get_byte/1 get_byte/2 get_char/1 get_code/1 get_code/2 peek_char/1 peek_char/2 peek_code/1 peek_code/2 prolog I/O put_char/1 put_char/2 put_code/1 put_code/2 nl/0 nl/1

Example
get_char(user_in, A). Assume there is an input stream called user_in and it has contents: q, w, e, ...
A is assigned the value q and the stream is left as: w, e, ...
get_char(user_in, 117). Assume there is an input stream called user_in and it has contents: q, w, e, ...
get_char/2 fails, and a character was removed from the stream, the stream is left as: w, e, ...

 

Exceptions  
Char is neither a variable nor an in_character a type_error(in_character, Char) is thrown
stream_or_alias is a variable an instantiation_error exception is thrown
stream_or_alias is neither a variable nor a stream term nor an alias a domain_error(stream_or_alias, Stream) exception is thrown, the variable Stream is assigned the incorrect stream_or_alias term
stream_or_alias is not associated with an open stream an existence_error(stream, Stream) exception is thrown
stream_or_alias is an output stream a permission_error(input, stream, Stream) exception is thrown
stream_or_alias is a binary stream a permission_error(input, binary_stream, InputStream) is thrown, the variable InputStream is assigned the stream which was used as the input stream
current input stream has properties end_of_stream(past) and eof_action(error) a permission_error(input, past_end_of_stream, InputStream) exception is thrown

 

 

info@trinc-prolog.com