I am working in Prolog, and am trying to read in from a file. The first line is a password. With the password, I want to be able to use special characters.
Here is the read file code:
readfile(Filename):-
open(Filename, read, Str),
read(Str, Thepassword),
read(Str, Thefirewall),
close(Str),
nb_setval(password, Thepassword),
nb_setval(firewall, Thefirewall).
This works fine until I change the password from brittany to britta!y, then I get ERROR: computer1.txt:1: Syntax error: Operator expected
.
Anyone know what I should do?
read/2
reads Prolog terms. What you probably want is to read the whole line regardless it is in Prolog syntax or not.In SWI Prolog you can use the predicate
read_line_to_codes/2
instead. (See the SWI manual entry). You must include the library withuse_module(library(readutil))
first.SICStus has a similar predicate called
read_line/1/2
.If you need an atom instead of a list of codes, you can convert it with
atom_codes/2
.