menu:-
write('press 1 for write data on file.'),nl,
write('press 2 for read data from file.'),nl,read(Y),start(Y),
write('do u want to continue y/n?'),read(X),(X=y,menu).
start(Y):-(Y=1,go;Y=2,process).
go:-write('please enter the data u want to write on the file.'),nl,
tell('C:\test\people.txt'),
see(user),
read(X),
write(X),nl,
write('end_of_file'),
nl,
told.
readWord(InStream,W) :- get0(InStream,Char),
checkCharAndReadRest(Char,Chars,InStream),
atom_chars(W,Chars).
checkCharAndReadRest(10,[],_) :- !. % Return
checkCharAndReadRest(32,[],_) :- !. % Space
checkCharAndReadRest(-1,[],_) :- !. % End of Stream
checkCharAndReadRest(end_of_file,[],_) :- !.
checkCharAndReadRest(Char,[Char|Chars],InStream) :- get0(InStream,NextChar),
checkCharAndReadRest(NextChar,Chars,InStream).
writeWord(end_of_file).
writeWord(X) :- write(X),nl.
process:- open('C:\test\people.txt', read, In), repeat, readWord(In,W), writeWord(W),
W==end_of_file,!, close(In).