SWI-Prolog write to file
io, prolog, windows
Solution
Thank you very much @CapelliC the below code , which I wrote it , works fine the read built-in predicate used to read terms and when reach to end of file it shows an error , instead I used read_line_to_codes
readfacts:-
open('output.txt',read,In),
repeat,
read_line_to_codes(In,X),writef(" "),
writef(X),nl,
X=end_of_file,!,
nl,
close(In).
writefacts:-
open('output.txt',write,Out),
write(Out,'Age(Peter,30)'),
write(Out,'Skin(Smith,Black).'),
close(Out).
Problem
I saw the below threads and they are very useful and related to my problem Writing in file | Swi-Prolog | Windows\ Prolog insert, modify and delete facts on a separated database text file I tried to use tell, told see , seen to read write from text files but I have the same result nothing is written on the file when (I open it and see that) , and on the read either the system read end_of_file or have an error displayed in a message or on the console Below is some samples of my work : ``` start1:- open('output.txt',write,OS), X = 'Hi all', write(OS,X), close(OS), open('output.txt',read,OS2), read(OS2,Input). start1:- absolute_file_name('X.data',Abs), open(Abs,write,Out), tell(Abs), write('HiAll'), told, close(Out), open(Abs,read,In), see('X.data'), read(X), seen, write(X). ```