Message-ID: <3813D291.5F1FF7A1@montana.com> From: bowman X-Mailer: Mozilla 4.07 [en] (X11; I; Linux 2.0.36 i586) MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: best way to read selected data from a file? References: <3812949e_2 AT news DOT chariot DOT net DOT au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 16 Date: Sun, 24 Oct 1999 21:46:25 -0600 NNTP-Posting-Host: 208.4.224.50 X-Trace: newsfeed.slurp.net 940859107 208.4.224.50 (Mon, 25 Oct 1999 08:45:07 CDT) NNTP-Posting-Date: Mon, 25 Oct 1999 08:45:07 CDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Ryan wrote: > > But what If I want to go straight to line 15 and read that line? 1. Make each line the same length. Then you can calculate the position as line length X line_no (first line is #0), fseek and read. 2. Or, for variable length lines, maintain a lookup table of their position when you write them. Write the table to a separate file, calling it something like my_file.key. Yes, file access is more complicated than many new programmers expect. Some library routines look for separators (\n for instance) and give you the feeling that the file is organized by 'lines', but it is really just a bunch of bytes. And, no, you cannot arbitrarily stick a number of extra bytes in the middle of an existing file.