| Deutsch English Français Italiano |
|
<871pw073if.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Buffer contents well-defined after fgets() reaches EOF ?
Date: Fri, 14 Feb 2025 11:03:20 -0800
Organization: None to speak of
Lines: 20
Message-ID: <871pw073if.fsf@nosuchdomain.example.com>
References: <vo9g74$fu8u$1@dont-email.me> <vo9hlo$g0to$1@dont-email.me>
<vo9khf$ggd4$1@dont-email.me> <vobf3h$sefh$2@dont-email.me>
<vobjdt$t5ka$1@dont-email.me> <vobkd5$t7np$1@dont-email.me>
<20250210124911.00006b31@yahoo.com> <86ldu9zxkb.fsf@linuxsc.com>
<20250214165108.00002984@yahoo.com> <20250214085627.815@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Fri, 14 Feb 2025 20:03:22 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a42ff31f5a4137896d7363f5acece8ee";
logging-data="3783916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3ZzQUosGAhYw5nHaM5RSc"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:3NX643Tjw9jHwSY6wwwJIgzp1cI=
sha1:I0j2a/9hGPzeOgEnkMgadurnxWM=
Bytes: 1934
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.com
void Void(void) { Void(); } /* The recursive call of the void */