Re: how get "number" in disk text file read into integer variable?
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Jan 30, 2000
- 537 views
A belated thanks to M.Kollenaar for code to write & read integers from a disk file; turns out I did need it after all, for a different part of my structured variable than what I was originally asking about. Dan Moyer -----Original Message----- From: M.Kollenaar <M.Kollenaar at SLO.NL> To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU> Date: Sunday, January 23, 2000 1:51 PM Subject: Re: how get "number" in disk text file read into integer variable? >Hi Dan, > >I use this code to write and read integers to and from a disk file. fn is a file >handle. > >global procedure PutDWord(integer fn, integer dw) >-- Writes a double word (4 bytes) to an open file. > puts(fn,int_to_bytes(dw)) >end procedure > >global function GetDWord(integer fn) >-- Reads an 32-bits integer from disk. >-- Speeding up thanks to Lucius L. Hilley III. > sequence w > > w = repeat(0,4) > for i = 1 to 4 do > w[i] = getc(fn) > end for > return bytes_to_int(w) >end function > >-- end code > >Dan B Moyer wrote: > >> Ok gang, here's my problem now <sigh!>: >> >> How do I get a "number" I have saved into a (text) disk file back as an >> integer? >> >> I'm trying to save a structured variable to a disk file & then be able to >> read it from the file & put it back into the structured variable. I'm >> using the >> "newex06d.exw" database example by Ad Rienks from the Tutorial as a starting >> point, & proceeding tiny steps at a time. >> >> My first step was to make a text file that would LOOK like the saved file >> should look like, and then just READ that file into my structured variable. >> Since part of my structured variable is of variable length, I put that >> length into a disk file (using a text editor), so it can be read out & used >> to count lines in the file to know what to put where in the structured >> variable. >> >> So if my first variant length is "3", I put the number 3 into the disk >> file on a line; but I can't seem to get that "3" back as an integer when I >> read it (I get 51, which is ASCII for 3). I'm guessing this is >> pathetically simple, but I can't get it. >> >> Dan Moyer