writing to Files 
Author Message
 writing to Files

Hi,

can someone of you tell me how to read from a file ?

see('sth.txt'),read(X),write(X),nl,seen.

doesn't seem to work.
how can i do this ?

Christoph



Sun, 09 May 2004 22:27:46 GMT  
 writing to Files
On Wed, 21 Nov 2001 15:27:46 +0100, Christoph Hermann

Quote:

>Hi,

>can someone of you tell me how to read from a file ?

>see('sth.txt'),read(X),write(X),nl,seen.

>doesn't seem to work.
>how can i do this ?

Maybe you should be a bit more specific on what doesn't
work and what is in sth.txt.  There is nothing wrong with
this program a such and it will work fine provided sth.txt
exists, can be accessed for reading and contains a valid
Prolog term terminated by a fullstop and blank character.
(your Prolog may be forgiving on the blank, but the standard
demands it).

If your sth.txt contains ordinary text, have a look at get0/1
for reading characters.

If you want a bit more modern code, have a look at open/3
and get_code/2.

        Regards --- Jan



Sun, 09 May 2004 23:55:29 GMT  
 writing to Files


Quote:
> exists, can be accessed for reading and contains a valid
> Prolog term terminated by a fullstop and blank character.

that was the Problem thanks :)

Now i have another Problem...
Given the following Code:

test:-readline('bla.txt',3,X),write(X),nl.
readline(File,Linenumber,Result):-see(File),readtheline(Linenumber,Resul
t,0),seen.

readtheline(Linenumber,Result,Linenumber):-!.
readtheline(Linenumber,Result,Current):-Y is Current + 1,write('2 '),
read(X), readtheline(Linenumber,X,Y).

the Procedure readtheline/3 works fine, a part of the fact, that at the
end, while exiting the recursion it resets the Var "Result".

   Call: (11) readtheline(3, testline3, 3) ? creep
   Exit: (11) readtheline(3, testline3, 3) ? creep
   Exit: (10) readtheline(3, testline2, 2) ? creep
   Exit: (9) readtheline(3, testline1, 1) ? creep
   Exit: (8) readtheline(3, _G336, 0) ? creep
                            ^^^^^^

bla.txt looks like this:

testline1.
testline2.
testline3.
...

Any hints how i can avoid this ?
Christoph



Mon, 10 May 2004 05:56:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. IMAQ Vision - Writing Image Files: File Format

2. purging file buffers - to make new data be written to file

3. writing FORTRAN files from C file pointers

4. [SQUEAK]Read/Write Source Files In Portable ANSI SIF

5. Read and write NFS-files

6. Writing to File Streams

7. Please help Visual Basic Programer with simple read/write text file routine---Real Basic 2.1

8. Grab records/write to file in AWK

9. Need to read/write graphics files

10. Writing text files

11. Writing gif files from smalltalk

12. BOSS without writing to files

 

 
Powered by phpBB® Forum Software