Re: Trouble reading bytes

new topic     » goto parent     » topic index » view thread      » older message » newer message

--- dstanger at belco.bc.ca wrote:
> 
> Im using this method to write the contents of a
> sequence to a file:
> 
> data = {{0,0,0,0,0},
>            {1,1,1,1,1},
>            {2,2,2,2,2},
>            {3,3,3,3,3}} 
> 
> fn = open("c:\file.dat", "w")
>      for i = 1 to length(data) do
>          puts(fn, data[i])
>      end for
> close(fn)
> 
> But when I read it back from the file into a
> sequence using getc() sometimes a -1 is returned
> rather than the number that I originally saved.
> Where am I going wrong?

You're going about this the hard way:
If, as you state, you want to save and retrieve 
data _as a sequence_, then try this:

fn = open("file.dat", "w")
  print(fn,data)
close(fn)

That saves the sequence as written:
{{0,0,0,0,0},{1,1,1,1,1},{2,2,2,2,2},{3,3,3,3,3}}

To read it back in _as a sequence_, use this:
fn = open("file.dat","r")
 data = get(fn) -- need to include get.e
 data = data[2]
 close(fn)

? data
{
  {0,0,0,0,0},
  {1,1,1,1,1},
  {2,2,2,2,2},
  {3,3,3,3,3}
}

Regards
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu