Re: Beginner seeks help
- Posted by JJProg at CYBERBURY.NET
Feb 28, 2000
EU>Hello, I'm very new to this and require help with a simple problem.
EU>How do I write numbers (as in -1000,256,1.384,-4.2) to a file and read them
EU>back later as numbers (as in my earlier definition)?
EU>I must be missing something, do I have to go through all the effort of
EU>converting to binary and back again?
EU>A text file would be preferred, but is not absolutely necessary.
EU>Thanks for your time,
EU>Aidan.
To write a number (any atom) or a sequence, you can use print:
integer f
f = open("filetowrite","w")
print(f,datatowrite)
close(f)
Note that when you open a file with the "w" or "wb" mode, it erases any
existing files. You can use "a" or "ab" to append stuff to the end of an
existing file, or you can get all the data you want from the file
before writing a new version with the "w" or "wb" mode.
To read it back, use get in get.e:
include get.e
integer f
object temp
f = open("filetoread","r")
temp = get(f)
if temp[1] = GET_SUCCESS then
data = temp[2]
else
-- There was an error reading the data
end if
close(f)
Jeff Fielding
|
Not Categorized, Please Help
|
|