[comp.sys.amiga.tech] Random Access Files in C

a1040@mindlink.UUCP (Robert Broughton) (08/04/90)

> 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.

Peter_Warren_Lee@cup.portal.com (08/04/90)

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?

  Peter_Warren_Lee@cup.portal.com

jms@tardis.Tymnet.COM (Joe Smith) (08/10/90)

In article <32425@cup.portal.com> Peter_Warren_Lee@cup.portal.com writes:
>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?

Check your manals for the lseek() function.  You can do your own random I/O
by putting an lseek in front of every write.  Since AmigaDOS (like Unix)
treats all files a sequential streams of bytes, you'll have to calculate
suitable values for lseek yourself.
-- 
Joe Smith (408)922-6220 | SMTP: jms@tardis.tymnet.com or jms@gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C41    | BIX: smithjoe | 12 PDP-10s still running! "POPJ P,"
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga speaks for me."