Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Reading lines from a file, eliminating CR and LF Date: Tue, 27 Dec 2016 12:24:10 -0800 Organization: None to speak of Lines: 27 Message-ID: References: <9a6e5204-d031-4070-88cb-8132072c5c68@googlegroups.com> <7285df88-1603-4edb-abba-b9c5e4172d34@googlegroups.com> <9ab352a9-d804-4eea-8263-219d68c6e821@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="88e2dd73917ffc55196cce595b1d2179"; logging-data="22797"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19d0bcCcniMisSDprQeoDHK" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:LZjd1zjmr2IoptQLoCuxDgI8rBc= sha1:xUYpCKmQ+l3ipGvU8LHZIEkdFIc= Xref: csiph.com comp.lang.c:100354 Barry Schwarz writes: > On Tue, 27 Dec 2016 09:59:57 -0800 (PST), Alla _ > wrote: [...] >> while(fgets(buffer, sizeof(buffer), input_file) != NULL) >> { >> >> //If CR is found, its index is less than LF index > > Still an unjustified assertion. That depends on just what it means. After fgets(), *either* the string contained in buffer contains exactly one LF character, which will be at the very end, *or* it contains no LF characters at all. If there is an LF character, then the index of a CR character (if any) must be less than the index of the LF character. But the comment doesn't cover the case where there is no LF character. (I haven't read the code to determine whether it's consistent with the comment.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"