Jan 11, 2010 #1 jayyy Programmer Mar 1, 2008 7 BE Hello, I have problems with read a simple txt file. If the txt file is just one number and I use this code : 19 ?- open('lezen.txt',read,S),read(S,X). I always get : ERROR: lezen.txt:1:0: Syntax error: Unexpected end of file what am I doing wrong?
Hello, I have problems with read a simple txt file. If the txt file is just one number and I use this code : 19 ?- open('lezen.txt',read,S),read(S,X). I always get : ERROR: lezen.txt:1:0: Syntax error: Unexpected end of file what am I doing wrong?
Jan 11, 2010 #2 joel76 Programmer Aug 31, 2008 295 FR read/2 is used to read prolog terms, you must end with a dot. Upvote 0 Downvote
Jan 11, 2010 Thread starter #3 jayyy Programmer Mar 1, 2008 7 BE is there a way to read files that doesn't end with a dot? Upvote 0 Downvote
Jan 11, 2010 #4 joel76 Programmer Aug 31, 2008 295 FR With SWI-Prolog, you can use read_line_to_codes/2. e.g Code: test :- open('c:/travail/developpements/prolog/toto.txt', read,S), read_line_to_codes(S,X), close(S), writeln(X). The file toto.txt contains "salut " you get 1 ?- test. [115, 97, 108, 117, 116] true. Click to expand... Upvote 0 Downvote
With SWI-Prolog, you can use read_line_to_codes/2. e.g Code: test :- open('c:/travail/developpements/prolog/toto.txt', read,S), read_line_to_codes(S,X), close(S), writeln(X). The file toto.txt contains "salut " you get 1 ?- test. [115, 97, 108, 117, 116] true. Click to expand...