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: Mon, 26 Dec 2016 13:50:51 -0800 Organization: None to speak of Lines: 30 Message-ID: References: <9a6e5204-d031-4070-88cb-8132072c5c68@googlegroups.com> <7285df88-1603-4edb-abba-b9c5e4172d34@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="31bc51d5e3749a4123ef9a48700d50f9"; logging-data="28765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ItAIscFKixbtR2uvUM9fm" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qtX25ityAXDGz7VxTMn8dh7fJY4= sha1:z56VlaRbGxNd51hFiUjEifnYXsI= Xref: csiph.com comp.lang.c:100308 Manfred writes: [...] > Just to mention this: no newline should not be an error condition: you > may have a line with no newline at the end of the file. Still such a > (last) line is a valid one. > (This was already mentioned by some else) Essentially correct; feel free to ignore the following language-lawyering. The C standard says that for a text stream, it's implementation-defined whether the final line requires a trailing '\n'. If it *is* required by the current implementation, the behavior of reading a text file with no '\n' on the last line is undefined. In practice, I believe that most implementations don't require a trailing '\n', which means that code that reads text files should be prepared for a final unterminated line. Whether a final end-of-line marker is required on a CSV file is a separate question, to which there's probably no one definitive answer. My suggestion would be to accept input with a missing final end-of-line marker, but to always write such a marker on output. -- 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"