Re: Writing records into fixed length record file....
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 11, 2004
- 400 views
John F Dutcher wrote: > > > Will it probably be my misfortune to discover that I cannot use puts() > to write a string into a fixed length file (as in update or replace data) > because puts() will append a trailing character(s) and mess up the file. > Looping thru putc() is kind of undesireable for many records. > There seems to be no counter-part to 'get_bytes' to do writes to a > fixed length file with fixed length records .... i.e. 'put_bytes' ?? Actually you *can* use puts() to do this. fh = open("thefile.dat", "ub") . . . pos_to_update = (recnum - 1) * recsize VOID = seek(fh, pos_to_update) newrec = get_bytes(fh, recsize) -- Read in existing record. newrec[x..y] = whatever --- Fill in the 'fields' in the record. . . . VOID = seek(fh, pos_to_update) puts(fh, newrec) -- Derek Parnell Melbourne, Australia