UNexpected end of file when use inputStream::endOfStream/0
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,
-
- Active Member
- Posts: 47
- Joined: 19 Sep 2011 8:54
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..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,
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),
!.
Example #2: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')
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(),
!.
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01