Re: Variable-sized lines of text in linked list



Scottman wrote:

So with this in place, how can I read in variable length lines,
malloc() the proper storage for each and pass the pointer to
addnode()?

Another way than has been mentioned is to read characters
recursively until end of line is detected (at which point you
know exactly how long the line actually is), allocate a buffer of
that size, and move all of the input into the newly-allocated
buffer before returning a pointer to the buffer to the calling
function.

Alternatively, you could limit the depth of recursion and create
a linked list of buffers that (collectively) contain the entire
line, and/or (optionally) push those buffers off to disk as they
were filled so as to not fail until your disk was completely
filled...

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
.



Relevant Pages

  • Re: Captureing stdout and useing it elsewhere.
    ... stdout to a variable, not a file. ... contents into any buffer you like. ... file on disk to which this data will ever be written. ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.programmer)
  • [PATCH 3/3] Add ext3 data=guarded mode
    ... buffer onto a list of things that must be written before a commit. ... a workqueue where the real work of updating the on disk i_size is done. ... When we start tracking guarded buffers on a given inode, ... and it also takes a reference on the buffer head. ...
    (Linux-Kernel)
  • Re: [PATCH RFC] ext3 data=guarded v6
    ... Fixup locking while deleting an orphan entry. ... Fixup O_DIRCECT disk i_size updates ... buffer onto a list of things that must be written before a commit. ... When we start tracking guarded buffers on a given inode, ...
    (Linux-Kernel)
  • [PATCH RFC] ext3 data=guarded v6
    ... Fixup locking while deleting an orphan entry. ... Fixup O_DIRCECT disk i_size updates ... buffer onto a list of things that must be written before a commit. ... When we start tracking guarded buffers on a given inode, ...
    (Linux-Kernel)
  • [net-next PATCH 4/5] igb: Add support for enabling VFs to PF driver.
    ... pointer to the hardware struct ... under the terms and conditions of the GNU General Public License, ... * @msg: The message buffer ... * returns SUCCESS if it successfully copied message into the buffer ...
    (Linux-Kernel)