Discussions related to Visual Prolog
billgates198606

UNexpected end of file when use inputStream::endOfStream/0

Unread post by billgates198606 »

using stream function to read term in a txt file all example in forum failed ,to read term in txt,why this powerful development tool can't do this easy work,
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

using stream function to read term in a txt file all example in forum failed ,to read term in txt,why this powerful development tool can't do this easy work,
I don't know what kind of problem are you experiencing. As of my experience Visual Prolog 7.4 is really awesome and simple compared to other lower version..

Can you please share the code that you've tried and which caused the failure for you ?

Example #1 :


If you are trying to read a data from file and want to consult with the internal Data base, here is the way,

Code: Select all

%Define a database class facts - myTerm     myTerm1 : (string, string, integer).     myTerm2 : (integer, string, integer).     myTerm3 : (integer).     myTerm4 : (integer, char).   predicates     onPushButtonClick : button::clickResponder. clauses     onPushButtonClick(_Source) = button::defaultAction:-         %Consult it - this will bring all the data from file to IDB         file::consult(@"E:\Term_Input.txt", myTerm),               !.
File data : E:\Term_Input.txt
myTerm1("Welcome", "To", 1)
myTerm1("Nice", "see", 1)
myTerm2(10, "Ten", 1)
myTerm2(20, "Twenty", 1)
myTerm3(100)
myTerm3(200)
myTerm4(100, 'A')
myTerm4(200, 'B')
Example #2:

To read a data from one file and write into another file,

Code: Select all

predicates     copyTextStream : (inputStream In, outputStream Out). clauses     copyTextStream(In, Out) :-         if not(In:endOfStream()) then             Out:write(In:readline(), "\n"),             copyTextStream(In, Out)         end if.     predicates     onPushButtonClick : button::clickResponder. clauses     onPushButtonClick(_Source) = button::defaultAction:-         InputFile = inputStream_file::openFile8("E:\\test.txt"),        %Input file         OutputFile = outputStream_file::openFile8("E:\\test2.txt"),  %Output file         copyTextStream2(InputFile, OutputFile),                            %Calling place for looping         %You must close the stream after you complete your progress         InputFile:close(),                                               OutputFile:close(),         !.
At the end, whatever the data reside on the Input file will be written on the output file -
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
User avatar
Thomas Linder Puls
VIP Member
Posts: 1399
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

It seems that other people does not have problems, so I expect it to be something you do.

Can we see the data you are trying to read and the code you use to read it? Then we may be able to give more precise details on what the problem is.
Regards Thomas Linder Puls
PDC
Post Reply