Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou Newsgroups: comp.lang.c Subject: Re: Buffer contents well-defined after fgets() reaches EOF ? Date: Sun, 9 Feb 2025 18:34:55 +0100 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Sun, 09 Feb 2025 18:34:56 +0100 (CET) Injection-Info: dont-email.me; posting-host="2863fb45892f80e3bb8d5dd8ab68d22c"; logging-data="799517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BX04c5Yf//xuTJ3FDEeTF" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:6ia4LX/mLAsgjVpGqRTOGiqLB74= In-Reply-To: X-Enigmail-Draft-Status: N1110 Bytes: 2132 On 09.02.2025 16:27, Andrey Tarasevich wrote: > On Sat 2/8/2025 11:13 PM, Janis Papanagnou wrote: >> But now I wanted to ignore all data that I got for fgets() != NULL >> in the loop. And I hoped that *after* the loop the last read data is >> still valid. > > As Michael already noted it depends on what you consider as the last > piece of valid data in your file. I have a strong opinion of a text file concerning line terminators; I answered that in my reply Michael. > Say, what do you want to see as "the > last line" in a file that ends with > > abracadabra\n > > ? > > Is "abracadabra" the last line? Or is the last line supposed to be empty > in this case? If "\n" is a string literal (2 characters, '\' and 'n') then it's an incomplete line (as to my standards), if it's meant as a control character then it's complete. (Similar with on old Apple/Macs and on DOS-alike systems.) Janis