Re: Question regarding fgets and new lines
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 24 Nov 2006 20:28:43 -0500
Eric Sosman wrote:
.... snip ...
FWIW, I took a somewhat different tack in my own gets()
replacement (I guess everybody writes one, sooner or later).
Mine follows the precedent of things like getenv(): the returned
pointer is only valid until the next call, when the buffer it
points to may be overwritten and/or moved or freed.
This approach has some disadvantages: for example, it would
be a pain to make it thread-friendly. On the other hand, it
localizes all the memory management inside the function, and the
signature `char *getline(FILE*)' is simple enough that even I can
remember it. (The older and feebler my gray cells get, the more
I value simplicity ...)
When I designed ggets I considered that signature, but I could see
no way of returning appropriate errors for both FILE problems, EOF,
and memory allocation problems.
I second the motion about easily remembered signatures.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
.
- Follow-Ups:
- Re: Question regarding fgets and new lines
- From: Keith Thompson
- Re: Question regarding fgets and new lines
- From: Eric Sosman
- Re: Question regarding fgets and new lines
- References:
- Question regarding fgets and new lines
- From: mellyshum123
- Re: Question regarding fgets and new lines
- From: Eric Sosman
- Re: Question regarding fgets and new lines
- From: CBFalconer
- Re: Question regarding fgets and new lines
- From: Roland Pibinger
- Re: Question regarding fgets and new lines
- From: CBFalconer
- Re: Question regarding fgets and new lines
- From: Eric Sosman
- Question regarding fgets and new lines
- Prev by Date: Re: using DLL
- Next by Date: Re: Most Interesting Bug Track Down
- Previous by thread: Re: Question regarding fgets and new lines
- Next by thread: Re: Question regarding fgets and new lines
- Index(es):
Relevant Pages
|
|