Sujet : Re: Buffer contents well-defined after fgets() reaches EOF ?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 14. Feb 2025, 20:03:20
Autres entêtes
Organisation : None to speak of
Message-ID : <871pw073if.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Gnus/5.13 (Gnus v5.13)
Kaz Kylheku <
643-408-1753@kylheku.com> writes:
[...]
It would be good if fgets nuked the terminating newline.
>
Many uses of fgets, after every operation, look for the newline
and nuke it, before doing anything else.
>
There is a nice idiom for that, by the way, which avoids an
temporary variable and if test:
>
line[strcspn(line, "\n")] = 0;
[...]
Then how do you detect a partial line? That can occur either if
the last line doesn't have a terminating newline (on systems that
permit it) or a line that's too long to fit in the array.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */