Re: Trouble reading bytes
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 01, 2003
- 469 views
> ----- Original Message -----=20 > >From: dstanger at belco.bc.ca=20 > >To: EUforum=20 > >Sent: Friday, August 01, 2003 8:17 AM > >Subject: Trouble reading bytes > > > > > >Im using this method to write the contents of a=20 > >sequence to a file: > > > >data =3D {{0,0,0,0,0}, > > {1,1,1,1,1}, > > {2,2,2,2,2}, > > {3,3,3,3,3}}=20 > > > >fn =3D open("c:\file.dat", "w") > > for i =3D 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? > > >=20 Of course, if you are actually trying to use bytes rather than = sequences, this is one way to read them back in...if you know the = existing structure' of the data on disk, that is... fn =3D open("c:\\file.dat", "rb") object res =20 res =3D repeat(-1,5) for i =3D 1 to 4 do for j =3D 1 to 5 do res[j] =3D getc(fn) end for ? res end for close(fn) --=20 Derek