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: Line read from csv file with fgets has two characters before the terminating one Date: Thu, 15 Dec 2016 22:58:51 -0800 Organization: None to speak of Lines: 42 Message-ID: References: <457d2715-2a7a-4131-8083-637dc0919fb3@googlegroups.com> <616cc4c3-d560-4146-8f03-93e76bedf1fd@googlegroups.com> <94c39458-6789-4eaa-b773-36bc4d2d9976@googlegroups.com> <5nr65c5eljh0h12807v0qgtihk4a9cp6ah@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="2210dc8e98a3c302beae7e7a325c3760"; logging-data="26521"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19r/Xm2RR07M0M1G1ZTvb93" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:CYa5zuU/2nVz5jtWVlD75jR/LbU= sha1:migUMZupVORHa3fK5+NF+zoXkGQ= Xref: csiph.com comp.lang.c:99600 Geoff writes: > On Thu, 15 Dec 2016 15:29:52 -0800, Keith Thompson > wrote: >>Geoff writes: >>> On Thu, 15 Dec 2016 09:09:19 +0000, Richard Heathfield >>> wrote: >>>>Excel is by Microsoft. Microsoft wrote Windows, which uses screwy line >>>>endings for text files. You don't think Excel might write a screwy text >>>>file even on MacOS, just out of sheer habit? >>> >>> Excel 2016 for Mac outputs 0D-only end of lines in csv files. >> >>Are you sure it's not 0A? > > Absolutely sure. But there are FOUR different csv format selections in > the Save As... dialog, only one of them outputs a single-byte EOL. > > The four selections are: > CSV UTF-8 (Comma delimited) (.csv) > Comma Separated Values (.csv) > Windows Comma Separated (.csv) > MS-DOS Comma Separated (.csv) > > Only the first one (CSV UTF-8) uses the 0D ending. All the others use > 0D, 0A. This was proven by using hexdump on a sample file. > > The CSV UTF-8 format is at the top of the list, under "Common > Formats". The other are listed as "Specialty Formats". Which means that a CSV file exported in "CSV-UTF-8" format is not a text file. If you try to open it with a text editor, it will likely appear as one very long line with no line endings at all (unless some MacOS editors still recognize pre-OSx text files). It means that "wc -l filename.csv" won't tell you how many lines are in the file. That's astonishing. -- 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"