Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read a txt file

Status
Not open for further replies.

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?




 
read/2 is used to read prolog terms, you must end with a dot.
 
is there a way to read files that doesn't end with a dot?
 
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.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top