SWI Prolog , how to assert data to txt file
This is my sample source code , I am using SWI Prolog , can someone tell me how to assert data that user key in to txt.file. I want save the data in to txt.file.
start :-display_menu.
display_menu:- repeat,
write('\n======Matching Partner System========='),
write('\n1.Enter开发者_运维问答 user information'),
write('\n0.exits'),
write('\nEnter your choice:'),
read(Choice),
selection(Choice),
Choice=0.
selection(1):-get_userinfo.
selection(0):-!.
get_userinfo:-write('\n***Enter User Information***'),
write('\nEnter Name:'),
read(Name),
write('\nEnter Gender:'),
read(Gender),
write('\nEnter Age:'),
read(Age),
not(agevalidation(Age)),
write('\nEnter the attributes'),
get_attribute(Attr),
assert(userInfo(Name,Gender,Age,Attr)).
get_attribute(Attr):- write('\nEnter the height'),
read(Height),
Attr=[Height].
agevalidation(Age):-Age<18,
write('\nEnter valid age..').
check the IO predicates; you will probably want to use open/3 and close/3 to open/close a file and then write/2.
like:
open('myfile.txt', write, S),
write(S,Data),
close(S).
精彩评论