www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/25/12:07:32

Message-ID: <3813D291.5F1FF7A1@montana.com>
From: bowman <bowman AT montana DOT com>
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>
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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019