Re: Variable-sized lines of text in linked list
- From: Morris Dovey <mrdovey@xxxxxxxx>
- Date: Thu, 28 Feb 2008 16:28:31 -0500
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
.
- Follow-Ups:
- Re: Variable-sized lines of text in linked list (long)
- From: Morris Dovey
- Re: Variable-sized lines of text in linked list (long)
- References:
- Variable-sized lines of text in linked list
- From: Scottman
- Variable-sized lines of text in linked list
- Prev by Date: Re: Compile error at testing Function Pointer
- Next by Date: Re: Variable-sized lines of text in linked list
- Previous by thread: Re: Variable-sized lines of text in linked list
- Next by thread: Re: Variable-sized lines of text in linked list (long)
- Index(es):
Relevant Pages
|