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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing out multiple answers to file.

Status
Not open for further replies.
Jun 23, 2008
1
0
0
GB
Hi,

I want to solve a query that can have multiple answers and I want the answers to be output to a text file.

The problem is that I can only get the first answer to output and not the rest.

My code is as follows.

solve:-
top_goal(X),
open('out.txt',append,OS),
write(OS,X),nl(OS),
close(OS).

Where top_goal is produces values for X.
Can anyone help?
Thanks in advance
 
phatassbob (MIS) 23 Jun 08 19:30
Hi,

I want to solve a query that can have multiple answers and I want the answers to be output to a text file.

The problem is that I can only get the first answer to output and not the rest.

My code is as follows.

solve:-
top_goal(X),
open('out.txt',append,OS),
write(OS,X),nl(OS),
close(OS).

Where top_goal is produces values for X.
Can anyone help?
Thanks in advance
__________________________________________

When you are closing the file -you will overwrite it the next time you open it. Subsequent writes without closing the file will append the file rather than re-writing it.

It's also uncertain which prolog you are using.
 
In SWI-Prolog, just add fail after close(OS):

solve:-
top_goal(X),
open('out.txt',append,OS),
write(OS,X),nl(OS),
close(OS),
fail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top