Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Program to read csv file, store characters and numbers in separate arrays |
| Date | 2016-12-15 19:31 +0000 |
| Organization | Fix this later |
| Message-ID | <o2uqvh$cct$1@dont-email.me> (permalink) |
| References | <09988b6c-e11e-4fd6-8731-7992d16c7b94@googlegroups.com> <o2u6sc$tq8$1@dont-email.me> <739ea08a-3cba-47bc-8e81-4a4e3d13bc59@googlegroups.com> <o2ug9j$2vj$1@dont-email.me> <200cb89f-ae11-4328-b9ee-7bc4e4b98866@googlegroups.com> |
On 15/12/16 17:25, Alla _ wrote: <snip> > Please, take a look at two versions of csv file I have posted in the first message: > the first one does have that trailing comma, and the second doesn't. > The first version has two trailing zeros, the second has one trailing zero; > I think that the zero I see when processing your file comes from the > newline character, which is all right because I don't stop the loop before > the '\n'. I'm going to show you four sets of test data, and four sets of results. The first set of test data is the CSV file I sent you. The second set is your first CSV file (the uppermost one in your article). The third set is your second CSV file (the lowermost one in your article). The fourth set is a CSV file that I have modified to illustrate a point, which we'll come to in its proper place. First, the test data I sent you: ++++ inc_st_test.csv ++++ Income Statement,2011,2012,2013,2014,2015 Sales,1062,1252,1587,1934,2519 Cost of Goods Sold,654,814,1009,1190,1499 Gross Profit,408,438,578,744,1020 "Selling, General, and Admin Exp",254,271,364,454,576 Operating Income before Depr,154,167,214,290,444 Depreciation and Amortization,25,31,38,52,70 Operating Profit,129,136,176,238,374 Interest Expense,4,3,3,1,4 Other Gains and Losses,0,7,10,0,-1 Pretax Income,125,126,163,237,371 Income Tax Expense,55,52,65,92,141 Net Income,70,74,98,145,230 ++++ end of inc_st_test.csv ++++ Results (first 5 lines only): (1) Income Statement,2011,2012,2013,2014,2015 (1.1) buffer length = 42 (2) Income Statement (2.2) buffer length = 25 (3) 2011 2012 2013 2014 2015 Note the ABSENCE of trailing 0s in those results. Now for the first file you posted. Note the trailing commas. ++++ test1.csv ++++ Years,2011,2012,2013,2014,2015, Sales,1062,1252,1587,1934,2519, Cost of Goods Sold,654,814,1009,1190,1499, Gross Profit,408,438,578,744,1020, SG&A,254,271,364,454,576, Operating Income before Depr,154,167,214,290,444, Depreciation and Amortization,25,31,38,52,70, Operating Profit,129,136,176,238,374, Interest Expense,4,3,3,1,4, Other Gains and Losses,0,7,10,0,-1, Pretax Income,125,126,163,237,371, Income Tax Expense,55,52,65,92,141, Net Income,70,74,98,145,230, ++++ end of test1.csv ++++ Results (first 5 lines only): (1) Years,2011,2012,2013,2014,2015, (1.1) buffer length = 32 (2) Years (2.2) buffer length = 26 (3) 2011 2012 2013 2014 2015 0 Note the trailing 0. Now for the second CSV file you posted, with NO trailing commas: ++++ test2.csv ++++ Years,2011,2012,2013,2014,2015 Sales,1062,1252,1587,1934,2519 Cost of Goods Sold,654,814,1009,1190,1499 Gross Profit,408,438,578,744,1020 "Selling, General, and Admin Exp",254,271,364,454,576 Operating Income before Depr,154,167,214,290,444 Depreciation and Amortization,25,31,38,52,70 Operating Profit,129,136,176,238,374 Interest Expense,4,3,3,1,4 Other Gains and Losses,0,7,10,0,-1 Pretax Income,125,126,163,237,371 Income Tax Expense,55,52,65,92,141 Net Income,70,74,98,145,230 ++++ end of test2.csv ++++ Again, note that there are no trailing commas. Results (first 5 lines only): (1) Years,2011,2012,2013,2014,2015 (1.1) buffer length = 31 (2) Years (2.2) buffer length = 25 (3) 2011 2012 2013 2014 2015 Note the ABSENCE of trailing 0s. Now for an experiment. For my fourth test, I will deliberately place some extra commas at the end of each line. ++++ test3.csv ++++ Years,2011,2012,2013,2014,2015,,, Sales,1062,1252,1587,1934,2519,,, Cost of Goods Sold,654,814,1009,1190,1499,,, Gross Profit,408,438,578,744,1020,,, SG&A,254,271,364,454,576,,, Operating Income before Depr,154,167,214,290,444,,, Depreciation and Amortization,25,31,38,52,70,,, Operating Profit,129,136,176,238,374,,, Interest Expense,4,3,3,1,4,,, Other Gains and Losses,0,7,10,0,-1,,, Pretax Income,125,126,163,237,371,,, Income Tax Expense,55,52,65,92,141,,, Net Income,70,74,98,145,230,,, ++++ end of test3.csv ++++ Note that there are THREE trailing commas at the end of each line. Prediction: 3 trailing 0s. Results (first 5 lines only): (1) Years,2011,2012,2013,2014,2015,,, (1.1) buffer length = 34 (2) Years (2.2) buffer length = 28 (3) 2011 2012 2013 2014 2015 0 0 0 Three trailing 0s. Hypothesis confirmed. The file I sent you has NO trailing commas, and NO trailing 0s. The file that I doctored to have THREE trailing commas has THREE trailing 0s. I conclude that each trailing comma produces a trailing 0 to match. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-15 05:05 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 13:48 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-15 08:22 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 16:28 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-15 09:25 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 19:31 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 01:19 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 10:01 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 02:43 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 11:03 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 03:08 -0800
Re: Program to read csv file, store characters and numbers in separate arrays jameskuyper@verizon.net - 2016-12-18 03:32 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Barry Schwarz <schwarzb@dqel.com> - 2016-12-16 17:09 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 01:25 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 10:11 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 02:45 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Keith Thompson <kst-u@mib.org> - 2016-12-16 09:54 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 17:56 +0000
Re: Program to read csv file, store characters and numbers in separate arrays gazelle@shell.xmission.com (Kenny McCormack) - 2016-12-16 18:02 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 03:06 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 11:28 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 12:02 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 12:41 +0000
Re: Program to read csv file, store characters and numbers in separate arrays BartC <bc@freeuk.com> - 2016-12-16 13:40 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 14:03 +0000
Re: Program to read csv file, store characters and numbers in separate arrays BartC <bc@freeuk.com> - 2016-12-16 13:03 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 15:04 +0000
Re: Program to read csv file, store characters and numbers in separate arrays BartC <bc@freeuk.com> - 2016-12-16 15:26 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 17:01 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 04:18 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 14:12 +0000
Re: Program to read csv file, store characters and numbers in separate arrays David Brown <david.brown@hesbynett.no> - 2016-12-15 16:14 +0100
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 15:37 +0000
Re: Program to read csv file, store characters and numbers in separate arrays David Brown <david.brown@hesbynett.no> - 2016-12-15 23:20 +0100
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 23:27 +0000
Re: Program to read csv file, store characters and numbers in separate arrays David Brown <david.brown@hesbynett.no> - 2016-12-16 12:10 +0100
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 11:43 +0000
Re: Program to read csv file, store characters and numbers in separate arrays David Brown <david.brown@hesbynett.no> - 2016-12-16 14:01 +0100
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 13:12 +0000
Re: Program to read csv file, store characters and numbers in separate arrays David Brown <david.brown@hesbynett.no> - 2016-12-16 14:57 +0100
Re: Program to read csv file, store characters and numbers in separate arrays BartC <bc@freeuk.com> - 2016-12-15 16:30 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 16:36 +0000
Re: Program to read csv file, store characters and numbers in separate arrays David Brown <david.brown@hesbynett.no> - 2016-12-15 23:29 +0100
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-15 08:26 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 16:33 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-15 08:32 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 16:37 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Keith Thompson <kst-u@mib.org> - 2016-12-15 12:17 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 01:33 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Keith Thompson <kst-u@mib.org> - 2016-12-15 12:23 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-15 20:39 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-15 21:13 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 00:39 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 08:54 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 01:09 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 09:32 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 01:51 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 10:08 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-16 11:09 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 03:16 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 03:20 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Keith Thompson <kst-u@mib.org> - 2016-12-16 09:48 -0800
Re: Program to read csv file, store characters and numbers in separate arrays gazelle@shell.xmission.com (Kenny McCormack) - 2016-12-16 17:55 +0000
Re: Program to read csv file, store characters and numbers in separate arrays raltbos@xs4all.nl (Richard Bos) - 2016-12-20 11:53 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 11:33 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Keith Thompson <kst-u@mib.org> - 2016-12-16 09:46 -0800
Re: Program to read csv file, store characters and numbers in separate arrays "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-03 15:38 -0500
Re: Program to read csv file, store characters and numbers in separate arrays Barry Schwarz <schwarzb@dqel.com> - 2016-12-15 12:36 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 01:44 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 10:04 +0000
Re: Program to read csv file, store characters and numbers in separate arrays Alla _ <modelling.data@gmail.com> - 2016-12-16 03:14 -0800
Re: Program to read csv file, store characters and numbers in separate arrays Richard Heathfield <rjh@cpax.org.uk> - 2016-12-16 11:46 +0000
csiph-web