Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!van-bc!rsoft!mindlink!a1040 From: a1040@mindlink.UUCP (Robert Broughton) Newsgroups: comp.sys.amiga.tech Subject: Re: Random Access Files in C Message-ID: <2714@mindlink.UUCP> Date: 3 Aug 90 23:17:12 GMT Organization: MIND LINK! - British Columbia, Canada Lines: 22 > Peter_Warren_Lee@cup.portal.com writes: > > >I'm just starting to play around with C and was browsing through a few > >books to see what kinds of commands were in the language. I saw some file > functions that appeared to be used for writing sequential files but I > didn't see anything that would handle random access files. Is there a > good way to do it in C? > > If your records are fixed length, all you have to do is multiply the record > length by the record number, and lseek() to that location. If your records > are variable-length, store the first byte of each record in an array, read > that array from the disk each time you open the file, and write it to disk > when you close it. > > If you want to do direct access using KEYS instead of "record numbers", buy a > copy of dBC III from Lattice. It is a set of C-callable functions which > process files in dBASE-style files and indexes. > > Finally, a philosophical note; C doesn't include FORTRAN-style random-access > for the same reason that it does not include a ** operator for > exponentiation. C was designed to avoid hiding what the > computer is actually doing from the programmer.