Re: Variable-sized lines of text in linked list




"Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx> wrote in message
news:ezKxj.679254$kj1.213468@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Scottman <FonzoCool@xxxxxxxxx> wrote in message
news:1fe49f6a-2abf-419d-9008-99ee0fc6cee7@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I am trying to read a text file into memory without any knowledge of
how long each line will be. I am looking to store each line in a
linked list structure, however, I am unsure of how to dynamically
allocate space for each line.

Maybe you don't have to malloc each line, but rather just the entire
file, with pointers to the start of each line, and replace each newline
with a terminating null (this decision will impact how easily you can
process the lines after you've stored them this way, but just throwing
out an idea that doesn't seem to be getting much play here).

Reading an entire file into memory is an admirable idea, but is frowned on
in this newsgroup for various reasons: the size of a file is impossible to
determine, or could change while you're reading the file, or because it
might be a 100GB monster you therefore should never attempt this even for
tiny files.

That doesn't mean you shouldn't do it; just keep quiet about it here :-)

--
Bart



.



Relevant Pages

  • Re: Variable-sized lines of text in linked list
    ... I am looking to store each line in a ... linked list structure, however, I am unsure of how to dynamically ... file, with pointers to the start of each line, and replace each newline ...
    (comp.lang.c)
  • Re: A question about fill_free_list(void) function
    ... I'm reading the CPython interpreter source code, ... The code is abusing the ob_type member to store a single linked, ... return (PyObject *) v; ...
    (comp.lang.python)
  • Re: Efficency and the standard library
    ... information in memory without reading it in, and do it in Otime. ... impossible, though, and store the data without reading it. ... each line consisting of a word terminated by a newline character. ... If you want an array of null pointers at startup, you'll have to make it static or put it at file scope. ...
    (comp.lang.c)
  • Re: Alternatives to Bifocals
    ... I have reading glasses for at home, ... It is a big pain in the ass to try to use bifocals on a computer all day, so this is a simple solution that may well cost less than Bi or Tri focals or progressive lens. ... I always carry both pair with me when I go to the store, and swap them when I get into the store so I can read labels and such. ...
    (soc.senior.issues)
  • Re: Data logging... how to.
    ... I need to measure a temperature, and store it for later readout. ... I will be using an AVR for temp. ... Now, after the year, the data will be shifted continously, so there will always be the latest data reading about 12 months back. ...
    (sci.electronics.design)