Re: Variable-sized lines of text in linked list
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 03:27:04 -0500
Richard Heathfield wrote:
CBFalconer said:
Scottman wrote:
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.
Just get the (short and simple) function ggets(), in ggets.zip.
...and be aware of its problems. Chuck, if you're going to keep on
pimping this function, shouldn't you at least warn people of its
shortcomings?
I don't consider them shortcomings. They are that, since the
routine can collect lines of ANY length, that if you can supply a
sufficiently long line without any line terminations (normally
meaning <return> chars typed) the routine will malloc sufficient
space. If you then fail to free that space (normally a memory leak
error) it won't be freed, and you can run out of memory. Unlikely
in practice, and requires careful programmer and user
concentration.
Similarly all users of malloc, calloc, or realloc should be warned
that repeated use or use for sufficiently large demands can run out
of memory.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com
.
- Follow-Ups:
- Re: Variable-sized lines of text in linked list
- From: Richard Heathfield
- Re: Variable-sized lines of text in linked list
- References:
- Variable-sized lines of text in linked list
- From: Scottman
- Re: Variable-sized lines of text in linked list
- From: CBFalconer
- Re: Variable-sized lines of text in linked list
- From: Richard Heathfield
- Variable-sized lines of text in linked list
- Prev by Date: Re: printf() causes core dump
- Next by Date: Re: fseek on a file opened with _popen
- Previous by thread: Re: Variable-sized lines of text in linked list
- Next by thread: Re: Variable-sized lines of text in linked list
- Index(es):
Relevant Pages
|