Deutsch English Français Italiano |
<voaokv$oad5$1@dont-email.me> 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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Buffer contents well-defined after fgets() reaches EOF ? Date: Sun, 9 Feb 2025 18:29:01 +0100 Organization: A noiseless patient Spider Lines: 47 Message-ID: <voaokv$oad5$1@dont-email.me> References: <vo9g74$fu8u$1@dont-email.me> <vo9hlo$g0to$1@dont-email.me> <vo9ki6$gib5$1@dont-email.me> <20250209125046.00001189@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Sun, 09 Feb 2025 18:29:03 +0100 (CET) Injection-Info: dont-email.me; posting-host="9f9c4a4d467cd7826f6af056aa0b049d"; logging-data="797093"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gZE6ciIeOYVCYqfRpqXFL" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:Zsn/KixvVnMg2j4mHXkvu9be1/o= X-Enigmail-Draft-Status: N1110 In-Reply-To: <20250209125046.00001189@yahoo.com> Bytes: 2671 On 09.02.2025 11:50, Michael S wrote: > On Sun, 9 Feb 2025 08:13:10 +0100 > Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: > [...] >> >> I have a _coherent_ file, with a few NL terminated lines of text. > > I wonder what you mean by "coherent". A badly chosen word; I noticed it too late only after posting. I meant consistent with respect to the line terminators (i.e. none missing, each line [including the last one] has one, no mixture of LF, CR, LR-LF, etc. (and also no fixed-sized unterminated lines as we may still know from mainframes, just to be complete). > >> Usually I use fgets() in contexts where I process every line, like >> >> while (fgets (buf, BUFSIZ, fd) != NULL) { >> operate_on (buf); >> } >> // here the status of buf[] is usually not important any more >> >> My actual context was different, like >> >> while (fgets (buf, BUFSIZ, fd) != NULL) { >> // buf[] contents are ignored here >> } >> operate_on (buf[]); // which I assumed contains last line >> > > It depends on definition of "last line". > What do you consider "last line" of the file in which last character is > not LF? I consider missing newlines at the end of any text line as a bug. (And I'm not inclined to use a weaker word than "bug".) YMMV. > The one before the last LF or one after? Your code would get > the latter. It's a non-issue (for me), as should have got obvious. Janis