Re: Question regarding fgets and new lines



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>


.



Relevant Pages

  • Re: Convertible top header latches
    ... My apologies. ... I copied my post from another that left out my signature. ... Any tips on replacement? ... interest in helping me out. ...
    (rec.autos.makers.chrysler)
  • Re: OT - Speed bandits
    ... Go to Account setting for your news server and turn off sending the ... ..vcf card. ... It's not a good replacement for your signature. ...
    (rec.outdoors.rv-travel)
  • Re: OT - Speed bandits
    ... Go to Account setting for your news server and turn off sending the ... ..vcf card. ... It's not a good replacement for your signature. ...
    (rec.outdoors.rv-travel)
  • Re: Sugababes on Davina
    ... Paul D wrote: ... Surely they are due for replacement any ... ceci, n'est pas un signature ...
    (uk.media.tv.misc)