Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #99491 > unrolled thread
| Started by | Alla _ <modelling.data@gmail.com> |
|---|---|
| First post | 2016-12-15 05:05 -0800 |
| Last post | 2016-12-16 11:46 +0000 |
| Articles | 20 on this page of 72 — 11 participants |
Back to article view | Back to comp.lang.c
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
Page 1 of 4 [1] 2 3 4 Next page →
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-15 05:05 -0800 |
| Subject | Program to read csv file, store characters and numbers in separate arrays |
| Message-ID | <09988b6c-e11e-4fd6-8731-7992d16c7b94@googlegroups.com> |
Hello!
I am not a fan of using exclamation marks, and any other text stressing effects,
so, instead of those, by resorting to a detailed and a bit verbose description below,
I hope to make myself clear in terms of what I am trying to achieve, which I often
fail to do )
Please, take a look at program, which:
1) opens the file csv, which name is provided by the user, or, if user has not
provided the file, open a specific file (my test file); I will post the contents
of two test csv files below the program;
2) reads contents of the file line by line, and counts the length of the line;
3) while reading each line:
- stores character values in the array_names;
- converts numerical characters into integers and stores those in the array_values;
4) I use printf as a debugging tool to check how each step of the program
performs; all these are separated from the program text with additional
newlines (yes, making the program vertically longer; sorry) and by comments
in capital letters.
Important part:
(1) please, please, please, do me a great favor and first read the
program to the end before starting saying how bad everything is, and what
a horrific code I have produced yet again, and don't stop at the beginning
lines of the code; the output I get is below the program and both csv inputs;
(2) please, note that I have decided to present this in one whole piece of
code without separating the program into functions; I will definitely separate
it later - I plan to take all pieces into separate functions;
(3) I will use a header file, in which I will store preprocessor commands, like
#define and #include, as well as functions' declarations, etc.;
for now, (2) and (3) are part of the same file;
(4) please, ignore array and buffer sizes for now; I have used these numbers
only for this test version for certain reasons.
(5) as I have written elsewhere, I am not testing for all possible conditions,
because there will be a separate notification for the user with a description
of csv file parameters required for the program; this is a student's program,
therefore I making lots of assumptions, and standardize the input information;
(6) I am working on certain improvements to this part, and will post them
later on; those are regarding the way I store values from the buffer.
(7) lengths of each line: I use strlen to see what is happening with the length
of the line; I have two files - the first one is the one I have converted and it
has two additional, yet undetected values at the end of each line before the
'\0'; another file, which is definitely a correct csv file, has been kindly
converted by Richard, and this one prints out additional 0 at the end of
each line upon converting numerical characters into integers.
Thank you very much!
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define BUFFER_SIZE 100
//#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
#define INCOME_STATEMENT "files/income_test.csv"
int main(int argc, char *argv[])
{
//check for correct number of arguments
if(argc > 2)
{
printf("Usage: program_name [file_name]");
return EXIT_FAILURE;
}
//determine a file to use
char *data_file = (argc == 2)? argv[1] : INCOME_STATEMENT;
FILE *fp = fopen(data_file, "r");
if ( fp )
{
char buffer[BUFFER_SIZE] = "";
char array_names[50][50];
int array_values[50][50];
char *ptr_buffer = NULL;
size_t i, j, k;
//Read each line from the file, store in the buffer
for ( i = 0; fgets(buffer, sizeof(buffer), fp) != NULL; ++i )
{
size_t buffer_length = strlen(buffer);
//DEBUG: CHECK IF BUFFER IS FILLED CORRECTLY
printf("(1) %s", buffer);
printf("(1.1) buffer length = %zu\n", buffer_length);
//DEBUG: CHECK IF NAMES ARE FILLED CORRECTLY
printf("(2) ");
//Parse row names from each line into 'array_names'
for ( j = 0, ptr_buffer = buffer; ( !isdigit(*ptr_buffer)); j++, ptr_buffer++ )
{
//Check if the line starts with double quotes
if(*ptr_buffer == '"')
{
//Skip double quotes
ptr_buffer++;
//Store every character between double quotes
while(*ptr_buffer != '"')
{
array_names[i][j] = *ptr_buffer++;
//DEBUG: CHECK IF NAMES ARE FILLED CORRECTLY
printf("%c", array_names[i][j]);
j++;
//Decrement the length of the buffer
buffer_length--;
}
ptr_buffer++;
}
/** THE IF STATEMENT THAT CHECKS FOR DOUBLE QUOTES WILL GO INTO A SEPARATE FUNCTION **/
if(*ptr_buffer == ',' && isdigit(*(ptr_buffer + 1)))
break;
array_names[i][j] = *ptr_buffer;
//DEBUG: CHECK IF NAMES ARE FILLED CORRECTLY
printf("%c", array_names[i][j]);
//Decrement the length of the buffer
buffer_length--;
}
array_names[i][j] = '\0';
putchar('\n');
//Move to the next character in the line beyond comma
ptr_buffer++;
buffer_length--;
//DEBUG: CHECK BUFFER LENGTH AFTER FILLING NAMES
printf("(2.2) buffer length = %zu\n", buffer_length);
//DEBUG: CHECK IF VALUES ARE FILLED CORRECTLY
printf("(3) ");
//Parse the comma-separated values from each line into 'array_values'
for ( k = 0; *ptr_buffer != '\0' /** && k < buffer_length - 2**/;
k++, ptr_buffer++)
{
array_values[i][k] = (int)strtol(ptr_buffer, &ptr_buffer,
10);
//DEBUG: CHECK IF VALUES ARE FILLED CORRECTLY
printf("%d ", array_values[i][k]);
}
printf("\n\n");
}
if (!feof(fp))
{
puts("Something went wrong with the provided file\n");
return EXIT_FAILURE;
}
fclose(fp);
}
//fopen() returned NULL
else
{
perror(data_file);
}
return 0;
}
First csv file, converted by me:
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,
Second csv file (a correct one in terms of csv format):
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
First output (will show only beginning parts of both outputs to shorten
the text):
(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
(1) Sales,1062,1252,1587,1934,2519,
(1.1) buffer length = 32
(2) Sales
(2.2) buffer length = 26
(3) 1062 1252 1587 1934 2519 0
(1) Cost of Goods Sold,654,814,1009,1190,1499,
(1.1) buffer length = 44
(2) Cost of Goods Sold
(2.2) buffer length = 25
(3) 654 814 1009 1190 1499 0 0
(1) Gross Profit,408,438,578,744,1020,
(1.1) buffer length = 38
(2) Gross Profit
(2.2) buffer length = 23
(3) 408 438 578 744 1020 0 0
(1) SG&A,254,271,364,454,576,
(1.1) buffer length = 27
(2) SG&A
(2.2) buffer length = 22
(3) 254 271 364 454 576 0 0
etc.
Second output:
(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
(1) Sales,1062,1252,1587,1934,2519
(1.1) buffer length = 32
(2) Sales
(2.2) buffer length = 26
(3) 1062 1252 1587 1934 2519 0
(1) Cost of Goods Sold,654,814,1009,1190,1499
(1.1) buffer length = 43
(2) Cost of Goods Sold
(2.2) buffer length = 24
(3) 654 814 1009 1190 1499 0
(1) Gross Profit,408,438,578,744,1020
(1.1) buffer length = 37
(2) Gross Profit
(2.2) buffer length = 22
(3) 408 438 578 744 1020 0
(1) "Selling, General, and Admin Exp",254,271,364,454,576
(1.1) buffer length = 55
(2) Selling, General, and Admin Exp
(2.2) buffer length = 23
(3) 254 271 364 454 576 0
etc.
[toc] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-15 13:48 +0000 |
| Message-ID | <o2u6sc$tq8$1@dont-email.me> |
| In reply to | #99491 |
On 15/12/16 13:05, Alla _ wrote: > Hello! > > (7) lengths of each line: I use strlen to see what is happening with the length > of the line; I have two files - the first one is the one I have converted and it > has two additional, yet undetected values at the end of each line before the > '\0'; another file, which is definitely a correct csv file, has been kindly > converted by Richard, and this one prints out additional 0 at the end of > each line upon converting numerical characters into integers. In this article, I'm only going to explain that trailing 0. And I'm going to try to do it in such a way that you can find the problem for yourself. Here is a sample from the file I sent you: Income Statement,2011,2012,2013,2014,2015 Here is a sample from the file that is causing you problems with a trailing 0: Years,2011,2012,2013,2014,2015, Let's compare them directly: Income Statement,2011,2012,2013,2014,2015 Years,2011,2012,2013,2014,2015, Now let's ignore the first field of each: 2011,2012,2013,2014,2015 2011,2012,2013,2014,2015, Do you see the difference? It's very slight, but it's very significant. Knowing the difference will, I think, enable you to see the problem, and it's a problem with your data, not your program. (Which isn't to say that the problem could not be dealt with in code. But in this case, I think it would be far simpler just to fix the data.) If I get time, I'll post code annotations separately. -- 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
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-15 08:22 -0800 |
| Message-ID | <739ea08a-3cba-47bc-8e81-4a4e3d13bc59@googlegroups.com> |
| In reply to | #99493 |
On Thursday, December 15, 2016 at 4:48:30 PM UTC+3, Richard Heathfield wrote: > On 15/12/16 13:05, Alla _ wrote: > > Hello! > > > > (7) lengths of each line: I use strlen to see what is happening with the length > > of the line; I have two files - the first one is the one I have converted and it > > has two additional, yet undetected values at the end of each line before the > > '\0'; another file, which is definitely a correct csv file, has been kindly > > converted by Richard, and this one prints out additional 0 at the end of > > each line upon converting numerical characters into integers. > > In this article, I'm only going to explain that trailing 0. And I'm > going to try to do it in such a way that you can find the problem for > yourself. > > Here is a sample from the file I sent you: > > Income Statement,2011,2012,2013,2014,2015 > > Here is a sample from the file that is causing you problems with a > trailing 0: > > Years,2011,2012,2013,2014,2015, > > Let's compare them directly: > > Income Statement,2011,2012,2013,2014,2015 > Years,2011,2012,2013,2014,2015, > > Now let's ignore the first field of each: > > 2011,2012,2013,2014,2015 > 2011,2012,2013,2014,2015, > > > Do you see the difference? It's very slight, but it's very significant. > Knowing the difference will, I think, enable you to see the problem, and > it's a problem with your data, not your program. (Which isn't to say > that the problem could not be dealt with in code. But in this case, I > think it would be far simpler just to fix the data.) > Thank you very much. Yes, I see the difference in that trailing comma. And the file that you have sent me (which is the second example I use; I have only corrected the name of the row in that file - years instead of income statement) produces one extra zero as can be seen in the output. Where could that zero come from?
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-15 16:28 +0000 |
| Message-ID | <o2ug9j$2vj$1@dont-email.me> |
| In reply to | #99513 |
On 15/12/16 16:22, Alla _ wrote: > On Thursday, December 15, 2016 at 4:48:30 PM UTC+3, Richard Heathfield wrote: >> On 15/12/16 13:05, Alla _ wrote: >>> Hello! >>> >>> (7) lengths of each line: I use strlen to see what is happening with the length >>> of the line; I have two files - the first one is the one I have converted and it >>> has two additional, yet undetected values at the end of each line before the >>> '\0'; another file, which is definitely a correct csv file, has been kindly >>> converted by Richard, and this one prints out additional 0 at the end of >>> each line upon converting numerical characters into integers. >> >> In this article, I'm only going to explain that trailing 0. And I'm >> going to try to do it in such a way that you can find the problem for >> yourself. >> >> Here is a sample from the file I sent you: >> >> Income Statement,2011,2012,2013,2014,2015 >> >> Here is a sample from the file that is causing you problems with a >> trailing 0: >> >> Years,2011,2012,2013,2014,2015, >> >> Let's compare them directly: >> >> Income Statement,2011,2012,2013,2014,2015 >> Years,2011,2012,2013,2014,2015, >> >> Now let's ignore the first field of each: >> >> 2011,2012,2013,2014,2015 >> 2011,2012,2013,2014,2015, >> >> >> Do you see the difference? It's very slight, but it's very significant. >> Knowing the difference will, I think, enable you to see the problem, and >> it's a problem with your data, not your program. (Which isn't to say >> that the problem could not be dealt with in code. But in this case, I >> think it would be far simpler just to fix the data.) >> > Thank you very much. Yes, I see the difference in that trailing comma. And the file > that you have sent me (which is the second example I use; I have only > corrected the name of the row in that file - years instead of income > statement) produces one extra zero as can be seen in the output. No, it doesn't. I just tested it here, and it's fine. I think you've got your test files muddled up. > Where could that zero come from? My data: 2011,2012,2013,2014,2015 Your data: 2011,2012,2013,2014,2015, My data doesn't produce the trailing zero. Yours does. Hence there is something significant about that trailing comma. Hint: how does your parsing routine know when it has processed the last field in one record line? -- 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
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-15 09:25 -0800 |
| Message-ID | <200cb89f-ae11-4328-b9ee-7bc4e4b98866@googlegroups.com> |
| In reply to | #99516 |
On Thursday, December 15, 2016 at 7:29:03 PM UTC+3, Richard Heathfield wrote: > On 15/12/16 16:22, Alla _ wrote: > > On Thursday, December 15, 2016 at 4:48:30 PM UTC+3, Richard Heathfield wrote: > >> On 15/12/16 13:05, Alla _ wrote: > >>> Hello! > >>><snip> > >> > > Thank you very much. Yes, I see the difference in that trailing comma. And the file > > that you have sent me (which is the second example I use; I have only > > corrected the name of the row in that file - years instead of income > > statement) produces one extra zero as can be seen in the output. > > No, it doesn't. I just tested it here, and it's fine. > > I think you've got your test files muddled up. > > > Where could that zero come from? > > My data: > 2011,2012,2013,2014,2015 > Your data: > 2011,2012,2013,2014,2015, > 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 will look it all this again. > My data doesn't produce the trailing zero. Yours does. Hence there is > something significant about that trailing comma. Hint: how does your > parsing routine know when it has processed the last field in one record > line? I use the null terminating character as the end of the line; initially I wanted to use the newline character, but had problems with the condition; I didn't get the correct output. That is why I have opened the csv topic in another thread. I have seen your hex program, so I have to give it a shot to see what's happening with my conversions. > > -- > 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
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-15 19:31 +0000 |
| Message-ID | <o2uqvh$cct$1@dont-email.me> |
| In reply to | #99534 |
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
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-16 01:19 -0800 |
| Message-ID | <88ab7754-4996-4bc0-a79d-d6605ab2a3db@googlegroups.com> |
| In reply to | #99551 |
On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote: > 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. > Great. We are working with exactly the same file, and you don't get any trailing zeros, while I get one - see in (3). (1) Income Statement,2011,2012,2013,2014,2015 (1.1) buffer length = 43 (2) Income Statement (2.2) buffer length = 26 (3) 2011 2012 2013 2014 2015 0 This is the evidence that there is something wrong with my ... have no idea what - machine, os, windows programs, bash...? <snip>
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-16 10:01 +0000 |
| Message-ID | <o30dve$np1$2@dont-email.me> |
| In reply to | #99608 |
On 16/12/16 09:19, Alla _ wrote: > On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote: >> 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. >> > Great. We are working with exactly the same file, > and you don't get any trailing zeros, while I get one > - see in (3). But I'm using the same code as you, so clearly we are /not/ using exactly the same file. Barry Schwarz has suggested that you may have a trailing space in your data, which wouldn't show up on Usenet, and he says (presumably after trying it out) that this will produce the symptom you are describing. -- 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
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-16 02:43 -0800 |
| Message-ID | <8ee864db-f4c7-4d04-8c87-2c2a9aa81d8e@googlegroups.com> |
| In reply to | #99617 |
On Friday, December 16, 2016 at 1:01:46 PM UTC+3, Richard Heathfield wrote: > On 16/12/16 09:19, Alla _ wrote: > > On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote: > >> 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. > >> > > Great. We are working with exactly the same file, > > and you don't get any trailing zeros, while I get one > > - see in (3). > > But I'm using the same code as you, so clearly we are /not/ using > exactly the same file. > Well, I have nothing to add here. One of the files I am using, and the one I have been referring in this discussion today, is the one you sent me. Are you using a different one? > Barry Schwarz has suggested that you may have a trailing space in your > data, which wouldn't show up on Usenet, and he says (presumably after > trying it out) that this will produce the symptom you are describing. I thought so too. I have tried manually to delete rows and columns around the data I need to preserve. I am out of tools, and definitely don't have any knowledge to continue figuring this out. But it is a huge problem for me as I can't proceed with working on the code because I can't even have the loop with a condition I need. I am thinking now how to solve the issue with the csv file. I will be back. >
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-16 11:03 +0000 |
| Message-ID | <o30hjp$3uv$1@dont-email.me> |
| In reply to | #99624 |
On 16/12/16 10:43, Alla _ wrote: > On Friday, December 16, 2016 at 1:01:46 PM UTC+3, Richard Heathfield wrote: >> On 16/12/16 09:19, Alla _ wrote: <snip> >>> Great. We are working with exactly the same file, >>> and you don't get any trailing zeros, while I get one >>> - see in (3). >> >> But I'm using the same code as you, so clearly we are /not/ using >> exactly the same file. >> > Well, I have nothing to add here. One of the files I am using, and the one > I have been referring in this discussion today, is the one you sent me. > Are you using a different one? No. Here's the hex dump, so you can see exactly what I'm using (and it's exactly what I sent you): 49 6E 63 6F 6D 65 20 53 74 61 74 65 6D 65 6E 74 |Income Statement| 2C 32 30 31 31 2C 32 30 31 32 2C 32 30 31 33 2C |,2011,2012,2013,| 32 30 31 34 2C 32 30 31 35 0A 53 61 6C 65 73 2C |2014,2015.Sales,| 31 30 36 32 2C 31 32 35 32 2C 31 35 38 37 2C 31 |1062,1252,1587,1| 39 33 34 2C 32 35 31 39 0A 43 6F 73 74 20 6F 66 |934,2519.Cost of| 20 47 6F 6F 64 73 20 53 6F 6C 64 2C 36 35 34 2C | Goods Sold,654,| 38 31 34 2C 31 30 30 39 2C 31 31 39 30 2C 31 34 |814,1009,1190,14| 39 39 0A 20 20 47 72 6F 73 73 20 50 72 6F 66 69 |99. Gross Profi| 74 2C 34 30 38 2C 34 33 38 2C 35 37 38 2C 37 34 |t,408,438,578,74| 34 2C 31 30 32 30 0A 22 53 65 6C 6C 69 6E 67 2C |4,1020."Selling,| 20 47 65 6E 65 72 61 6C 2C 20 61 6E 64 20 41 64 | General, and Ad| 6D 69 6E 20 45 78 70 22 2C 32 35 34 2C 32 37 31 |min Exp",254,271| 2C 33 36 34 2C 34 35 34 2C 35 37 36 0A 20 20 4F |,364,454,576. O| 70 65 72 61 74 69 6E 67 20 49 6E 63 6F 6D 65 20 |perating Income | 62 65 66 6F 72 65 20 44 65 70 72 2C 31 35 34 2C |before Depr,154,| 31 36 37 2C 32 31 34 2C 32 39 30 2C 34 34 34 0A |167,214,290,444.| 44 65 70 72 65 63 69 61 74 69 6F 6E 20 61 6E 64 |Depreciation and| 20 41 6D 6F 72 74 69 7A 61 74 69 6F 6E 2C 32 35 | Amortization,25| 2C 33 31 2C 33 38 2C 35 32 2C 37 30 0A 20 20 4F |,31,38,52,70. O| 70 65 72 61 74 69 6E 67 20 50 72 6F 66 69 74 2C |perating Profit,| 31 32 39 2C 31 33 36 2C 31 37 36 2C 32 33 38 2C |129,136,176,238,| 33 37 34 0A 49 6E 74 65 72 65 73 74 20 45 78 70 |374.Interest Exp| 65 6E 73 65 2C 34 2C 33 2C 33 2C 31 2C 34 0A 4F |ense,4,3,3,1,4.O| 74 68 65 72 20 47 61 69 6E 73 20 61 6E 64 20 4C |ther Gains and L| 6F 73 73 65 73 2C 30 2C 37 2C 31 30 2C 30 2C 2D |osses,0,7,10,0,-| 31 0A 20 20 50 72 65 74 61 78 20 49 6E 63 6F 6D |1. Pretax Incom| 65 2C 31 32 35 2C 31 32 36 2C 31 36 33 2C 32 33 |e,125,126,163,23| 37 2C 33 37 31 0A 49 6E 63 6F 6D 65 20 54 61 78 |7,371.Income Tax| 20 45 78 70 65 6E 73 65 2C 35 35 2C 35 32 2C 36 | Expense,55,52,6| 35 2C 39 32 2C 31 34 31 0A 20 20 4E 65 74 20 49 |5,92,141. Net I| 6E 63 6F 6D 65 2C 37 30 2C 37 34 2C 39 38 2C 31 |ncome,70,74,98,1| 34 35 2C 32 33 30 0A |45,230.| > >> Barry Schwarz has suggested that you may have a trailing space in your >> data, which wouldn't show up on Usenet, and he says (presumably after >> trying it out) that this will produce the symptom you are describing. > I thought so too. I have tried manually to delete rows and columns around > the data I need to preserve. I am out of tools, No, you are *not* out of tools. What you have is a reluctance to use a hex dump. Overcome that reluctance, and paste a hex dump of the file that is causing you problems. -- 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
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-16 03:08 -0800 |
| Message-ID | <46126560-d68c-4c87-8b4f-18237d1177de@googlegroups.com> |
| In reply to | #99626 |
On Friday, December 16, 2016 at 2:03:48 PM UTC+3, Richard Heathfield wrote: > On 16/12/16 10:43, Alla _ wrote: > > On Friday, December 16, 2016 at 1:01:46 PM UTC+3, Richard Heathfield wrote: > >> On 16/12/16 09:19, Alla _ wrote: > <snip> > >>> Great. We are working with exactly the same file, > >>> and you don't get any trailing zeros, while I get one > >>> - see in (3). > >> > >> But I'm using the same code as you, so clearly we are /not/ using > >> exactly the same file. > >> > > Well, I have nothing to add here. One of the files I am using, and the one > > I have been referring in this discussion today, is the one you sent me. > > Are you using a different one? > > No. Here's the hex dump, so you can see exactly what I'm using (and it's > exactly what I sent you): > > 49 6E 63 6F 6D 65 20 53 74 61 74 65 6D 65 6E 74 |Income Statement| > 2C 32 30 31 31 2C 32 30 31 32 2C 32 30 31 33 2C |,2011,2012,2013,| > 32 30 31 34 2C 32 30 31 35 0A 53 61 6C 65 73 2C |2014,2015.Sales,| > 31 30 36 32 2C 31 32 35 32 2C 31 35 38 37 2C 31 |1062,1252,1587,1| > 39 33 34 2C 32 35 31 39 0A 43 6F 73 74 20 6F 66 |934,2519.Cost of| > 20 47 6F 6F 64 73 20 53 6F 6C 64 2C 36 35 34 2C | Goods Sold,654,| > 38 31 34 2C 31 30 30 39 2C 31 31 39 30 2C 31 34 |814,1009,1190,14| > 39 39 0A 20 20 47 72 6F 73 73 20 50 72 6F 66 69 |99. Gross Profi| > 74 2C 34 30 38 2C 34 33 38 2C 35 37 38 2C 37 34 |t,408,438,578,74| > 34 2C 31 30 32 30 0A 22 53 65 6C 6C 69 6E 67 2C |4,1020."Selling,| > 20 47 65 6E 65 72 61 6C 2C 20 61 6E 64 20 41 64 | General, and Ad| > 6D 69 6E 20 45 78 70 22 2C 32 35 34 2C 32 37 31 |min Exp",254,271| > 2C 33 36 34 2C 34 35 34 2C 35 37 36 0A 20 20 4F |,364,454,576. O| > 70 65 72 61 74 69 6E 67 20 49 6E 63 6F 6D 65 20 |perating Income | > 62 65 66 6F 72 65 20 44 65 70 72 2C 31 35 34 2C |before Depr,154,| > 31 36 37 2C 32 31 34 2C 32 39 30 2C 34 34 34 0A |167,214,290,444.| > 44 65 70 72 65 63 69 61 74 69 6F 6E 20 61 6E 64 |Depreciation and| > 20 41 6D 6F 72 74 69 7A 61 74 69 6F 6E 2C 32 35 | Amortization,25| > 2C 33 31 2C 33 38 2C 35 32 2C 37 30 0A 20 20 4F |,31,38,52,70. O| > 70 65 72 61 74 69 6E 67 20 50 72 6F 66 69 74 2C |perating Profit,| > 31 32 39 2C 31 33 36 2C 31 37 36 2C 32 33 38 2C |129,136,176,238,| > 33 37 34 0A 49 6E 74 65 72 65 73 74 20 45 78 70 |374.Interest Exp| > 65 6E 73 65 2C 34 2C 33 2C 33 2C 31 2C 34 0A 4F |ense,4,3,3,1,4.O| > 74 68 65 72 20 47 61 69 6E 73 20 61 6E 64 20 4C |ther Gains and L| > 6F 73 73 65 73 2C 30 2C 37 2C 31 30 2C 30 2C 2D |osses,0,7,10,0,-| > 31 0A 20 20 50 72 65 74 61 78 20 49 6E 63 6F 6D |1. Pretax Incom| > 65 2C 31 32 35 2C 31 32 36 2C 31 36 33 2C 32 33 |e,125,126,163,23| > 37 2C 33 37 31 0A 49 6E 63 6F 6D 65 20 54 61 78 |7,371.Income Tax| > 20 45 78 70 65 6E 73 65 2C 35 35 2C 35 32 2C 36 | Expense,55,52,6| > 35 2C 39 32 2C 31 34 31 0A 20 20 4E 65 74 20 49 |5,92,141. Net I| > 6E 63 6F 6D 65 2C 37 30 2C 37 34 2C 39 38 2C 31 |ncome,70,74,98,1| > 34 35 2C 32 33 30 0A |45,230.| > > > > > >> Barry Schwarz has suggested that you may have a trailing space in your > >> data, which wouldn't show up on Usenet, and he says (presumably after > >> trying it out) that this will produce the symptom you are describing. > > I thought so too. I have tried manually to delete rows and columns around > > the data I need to preserve. I am out of tools, > > No, you are *not* out of tools. What you have is a reluctance to use a > hex dump. Overcome that reluctance, and paste a hex dump of the file > that is causing you problems. > Oh no, I am not reluctant, it is not true ) The word "reluctant" is not applicable to me )
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@verizon.net |
|---|---|
| Date | 2016-12-18 03:32 -0800 |
| Message-ID | <e09fe80e-c037-4370-9678-621a2dd1d916@googlegroups.com> |
| In reply to | #99629 |
Then what term would you use to describe the fact that it took multiple requests to get you to do this?
[toc] | [prev] | [next] | [standalone]
| From | Barry Schwarz <schwarzb@dqel.com> |
|---|---|
| Date | 2016-12-16 17:09 -0800 |
| Message-ID | <nv295cp7bk7sgtrhduptapl3vetuanhk5v@4ax.com> |
| In reply to | #99624 |
On Fri, 16 Dec 2016 02:43:26 -0800 (PST), Alla _
<modelling.data@gmail.com> wrote:
>On Friday, December 16, 2016 at 1:01:46 PM UTC+3, Richard Heathfield wrote:
<snip>
>> Barry Schwarz has suggested that you may have a trailing space in your
>> data, which wouldn't show up on Usenet, and he says (presumably after
>> trying it out) that this will produce the symptom you are describing.
>I thought so too. I have tried manually to delete rows and columns around
>the data I need to preserve. I am out of tools, and definitely don't have
>any knowledge to continue figuring this out. But it is a huge problem for
>me as I can't proceed with working on the code because I can't even have
>the loop with a condition I need. I am thinking now how to solve the issue
>with the csv file. I will be back.
You certainly do have the tools:
Read a record with fgets.
Test for the \n with strchr.
If \n present, replace it with some character not in your text,
such as #, @, !, or _
Print the string with printf using a format string similar to
"record = <%s>\n". This will show you if there is any "invisible"
text, such as blanks, at either end of the record.
If you think there might be unprintable characters in the text, add
the following before the call to printf:
Loop through characters
Test the current character with isprint.
If not printable, replace the character with another
unexpected character such as ? or ~.
You could also solve the problem of the extra "0" due to the
superfluous blank by testing the output of strtol. Using the
parameter names in the standard, if the value of *endptr equals the
value of nptr, then strtol performed no conversion. Therefore the
resulting 0 returned by strtol is not a value you are interested in.
--
Remove del for email
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-16 01:25 -0800 |
| Message-ID | <502dcf9d-7e33-4ea8-9306-8c53456af93a@googlegroups.com> |
| In reply to | #99551 |
On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote: > 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. > As we have discussed with Keith previously, it does seem that whenever I save a file as csv I get some trailing commas - they appear as the very last row, which has a few commas, only commas; and they don't disappear even if I manually delete about 500 rows in the excel file; what's also interesting is that I seem to get some hidden commas at the end of each row, even in the the file you have sent me, i.e. in the file correctly converted to csv. This issue has nothing to do with C, therefore I guess I have to opt out from posting questions on this matter here, and try to figure out how to solve this problem - I wish I knew more about computers and software to at least know where to look for the solution; I think I have to report to Microsoft and see what they say. I am sorry for posting so may words on topic not related to C. I know that people here might get annoyed with it, but I do hope for your understanding. <snip>
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-16 10:11 +0000 |
| Message-ID | <o30eii$q7r$1@dont-email.me> |
| In reply to | #99609 |
On 16/12/16 09:25, Alla _ wrote: > On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote: >> 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. >> > As we have discussed with Keith previously, it does seem that whenever > I save a file as csv I get some trailing commas - they appear as the very > last row, which has a few commas, only commas; and they don't disappear > even if I manually delete about 500 rows in the excel file; Then that should make an interesting little program for you to write: excelcsv_to_propercsv.c > what's also > interesting is that I seem to get some hidden commas at the end of each > row, even in the the file you have sent me, Are you saying your email program is corrupting data that is emailed to you? That seems very unlikely. But it's easily resolved. Show me a hex dump of the file I sent you, and let's find out whether it really has any hidden commas in it. > i.e. in the file correctly converted > to csv. This issue has nothing to do with C, therefore I guess I have to > opt out from posting questions on this matter here, and try to figure out > how to solve this problem - I wish I knew more about computers and > software to at least know where to look for the solution; I think I have to > report to Microsoft and see what they say. Not much point in doing that. First you need to establish exactly what is going on, and the hex dump is the solution to that. Once you know that, the chances are that any contact with MS will be a waste of their time and yours. Hex dump, please. -- 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
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-16 02:45 -0800 |
| Message-ID | <16bac630-590c-4722-bc4f-b7d0519c7746@googlegroups.com> |
| In reply to | #99620 |
On Friday, December 16, 2016 at 1:11:58 PM UTC+3, Richard Heathfield wrote: > On 16/12/16 09:25, Alla _ wrote: > > On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote: > >> 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. > >> > > As we have discussed with Keith previously, it does seem that whenever > > I save a file as csv I get some trailing commas - they appear as the very > > last row, which has a few commas, only commas; and they don't disappear > > even if I manually delete about 500 rows in the excel file; > > Then that should make an interesting little program for you to write: > excelcsv_to_propercsv.c > > > what's also > > interesting is that I seem to get some hidden commas at the end of each > > row, even in the the file you have sent me, > > Are you saying your email program is corrupting data that is emailed to > you? That seems very unlikely. But it's easily resolved. Show me a hex > dump of the file I sent you, and let's find out whether it really has > any hidden commas in it. > > > i.e. in the file correctly converted > > to csv. This issue has nothing to do with C, therefore I guess I have to > > opt out from posting questions on this matter here, and try to figure out > > how to solve this problem - I wish I knew more about computers and > > software to at least know where to look for the solution; I think I have to > > report to Microsoft and see what they say. > > Not much point in doing that. First you need to establish exactly what > is going on, and the hex dump is the solution to that. Once you know > that, the chances are that any contact with MS will be a waste of their > time and yours. > > Hex dump, please. > Yes, Sir.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2016-12-16 09:54 -0800 |
| Message-ID | <lnmvfvkbeh.fsf@kst-u.example.com> |
| In reply to | #99625 |
Alla _ <modelling.data@gmail.com> writes:
> On Friday, December 16, 2016 at 1:11:58 PM UTC+3, Richard Heathfield wrote:
[155 lines deleted]
>> Hex dump, please.
>>
> Yes, Sir.
Alla, you *really* didn't need to post that.
You posted a followup quoting Richard's entire message, which included
multiple levels of quotations from previous messages, most of them
irrelevant. And the only thing you added was a statement that you're
*going to* provide a hex dump.
You should have simply posted a followup containingt the hex dump --
preferably with most of the previous irrelevant context snipped (but of
course keeping attribution lines for any quoted text you keep).
My newsreader, like many others, does not collapse quoted text, at least
not by default. I had to scroll through the entire article to find the
one line you added in your response. When you fail to snip irrelevant
context, you're forcing most of the rest of us to scroll past it.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
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"
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2016-12-16 17:56 +0000 |
| Message-ID | <o319pk$pj9$1@dont-email.me> |
| In reply to | #99673 |
On 16/12/16 17:54, Keith Thompson wrote: > Alla _ <modelling.data@gmail.com> writes: >> On Friday, December 16, 2016 at 1:11:58 PM UTC+3, Richard Heathfield wrote: > [155 lines deleted] >>> Hex dump, please. >>> >> Yes, Sir. > > Alla, you *really* didn't need to post that. > > You posted a followup quoting Richard's entire message, which included > multiple levels of quotations from previous messages, most of them > irrelevant. And the only thing you added was a statement that you're > *going to* provide a hex dump. Partly my fault. I should have snipped more in my own article. Apologies. -- 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
[toc] | [prev] | [next] | [standalone]
| From | gazelle@shell.xmission.com (Kenny McCormack) |
|---|---|
| Date | 2016-12-16 18:02 +0000 |
| Message-ID | <o31a8d$aa3$2@news.xmission.com> |
| In reply to | #99673 |
In article <lnmvfvkbeh.fsf@kst-u.example.com>, Keith Thompson <kst-u@mib.org> wrote: ... >You should have simply posted a followup containingt the hex dump -- >preferably with most of the previous irrelevant context snipped (but of >course keeping attribution lines for any quoted text you keep). It is hard enough on poor Keith to be the topicality police, now he also has been saddled with the responsibility of being the posting etiquette police. >My newsreader, like many others, does not collapse quoted text, at least >not by default. I had to scroll through the entire article to find the >one line you added in your response. When you fail to snip irrelevant >context, you're forcing most of the rest of us to scroll past it. Somebody should teach Keith about the "tab" key (at least that's the key in trn; I'm sure other Unix 'text-y' newsreaders have something similar). Blaming the inadequacies of one's newsreader (or one's knowledge of how to use it) on some poor hapless newbie, is really bad form. -- The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL: http://user.xmission.com/~gazelle/Sigs/ForFoxViewers
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2016-12-16 03:06 -0800 |
| Message-ID | <e87be1fa-364e-4117-b4b0-7c81b89a3406@googlegroups.com> |
| In reply to | #99620 |
On Friday, December 16, 2016 at 1:11:58 PM UTC+3, Richard Heathfield wrote:
> On 16/12/16 09:25, Alla _ wrote:
> > On Thursday, December 15, 2016 at 10:31:28 PM UTC+3, Richard Heathfield wrote:
> >> On 15/12/16 17:25, Alla _ wrote:
<snip>
> Hex dump, please.
>
Below I post:
(1) The corrected version of the program based on comments I have received;
(2) csv inputs
(3) program's outputs
(4) hex dumps for each csv
Interesting: now that I have changed the error checking method, i.e. if (!ferror(fp)),
instead of checking for !feof, I get the error message at the end of the whole output;
this is telling me that there is something wrong with every csv file.
(1) ******Program******
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define BUFFER_SIZE 100
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
#define INCOME_STATEMENT "files/income_test.csv"
int main(int argc, char *argv[])
{
//Check for correct number of arguments
if(argc > 2)
{
fputs("Sorry, the program processes only one file.\n", stderr);
return EXIT_FAILURE;
}
//Determine a file to use
const char *data_file = (argc == 2)? argv[1] : INCOME_STATEMENT;
FILE *fp = fopen(data_file, "r");
if ( fp )
{
char buffer[BUFFER_SIZE] = "";
char array_names[50][50] = {{0}};
int array_values[50][50] = {{0}};
char *ptr_buffer = NULL;
size_t line_number = 0;
size_t names_column_number;
size_t values_column_number;
//Read each line from the file, store in the buffer
while(fgets(buffer, sizeof(buffer), fp) != NULL)
{
size_t buffer_length = strlen(buffer);
//DEBUG: CHECK IF BUFFER IS FILLED CORRECTLY
printf("(1) %s", buffer);
printf("(1.1) buffer length = %zu\n", buffer_length);
//DEBUG: CHECK IF NAMES ARE FILLED CORRECTLY
printf("(2) ");
//Parse row names from each line into 'array_names'
for ( names_column_number = 0, ptr_buffer = buffer;
( !isdigit(*ptr_buffer)); names_column_number++,
ptr_buffer++ )
{
//Check if the line starts with double quotes
if(*ptr_buffer == '"')
{
//Skip double quotes
ptr_buffer++;
//Store every character between double quotes
while(*ptr_buffer != '"')
{
array_names[line_number][names_column_number] = *ptr_buffer++;
//DEBUG: CHECK IF NAMES ARE FILLED CORRECTLY
printf("%c", array_names[line_number][names_column_number]);
names_column_number++;
//Decrement the length of the buffer
buffer_length--;
}
ptr_buffer++;
}
/** THE IF STATEMENT THAT CHECKS FOR DOUBLE QUOTES WILL GO INTO A SEPARATE FUNCTION **/
if(*ptr_buffer == ',' && isdigit(*(ptr_buffer + 1)))
break;
array_names[line_number][names_column_number] = *ptr_buffer;
//DEBUG: CHECK IF NAMES ARE FILLED CORRECTLY
printf("%c", array_names[line_number][names_column_number]);
//Decrement the length of the buffer
buffer_length--;
}
array_names[line_number][names_column_number] = '\0';
putchar('\n');
//Move to the next character in the line beyond comma
ptr_buffer++;
buffer_length--;
//DEBUG: CHECK BUFFER LENGTH AFTER FILLING NAMES
printf("(2.2) buffer length = %zu\n", buffer_length);
//DEBUG: CHECK IF VALUES ARE FILLED CORRECTLY
printf("(3) ");
//Parse the comma-separated values from each line into 'array_values'
for ( values_column_number = 0; *ptr_buffer != '\0'
/** && k < buffer_length - 2**/;
values_column_number++, ptr_buffer++)
{
array_values[line_number][values_column_number] = (int)strtol(ptr_buffer, &ptr_buffer,
10);
//DEBUG: CHECK IF VALUES ARE FILLED CORRECTLY
printf("%d ", array_values[line_number][values_column_number]);
}
printf("\n\n");
line_number++;
}
if (!ferror(fp))
{
puts("Something went wrong with the provided file\n");
return EXIT_FAILURE;
}
fclose(fp);
}
//fopen() returned NULL
else
{
perror(data_file);
}
return 0;
}
(2) File you have sent me (without changing Income
statement to Years in the first row):
******csv file******
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
******code output with one trailing zero******
(1) Income Statement,2011,2012,2013,2014,2015
(1.1) buffer length = 43
(2) Income Statement
(2.2) buffer length = 26
(3) 2011 2012 2013 2014 2015 0
(1) Sales,1062,1252,1587,1934,2519
(1.1) buffer length = 32
(2) Sales
(2.2) buffer length = 26
(3) 1062 1252 1587 1934 2519 0
(1) Cost of Goods Sold,654,814,1009,1190,1499
(1.1) buffer length = 43
(2) Cost of Goods Sold
(2.2) buffer length = 24
(3) 654 814 1009 1190 1499 0
(1) Gross Profit,408,438,578,744,1020
(1.1) buffer length = 37
(2) Gross Profit
(2.2) buffer length = 22
(3) 408 438 578 744 1020 0
(1) "Selling, General, and Admin Exp",254,271,364,454,576
(1.1) buffer length = 55
(2) Selling, General, and Admin Exp
(2.2) buffer length = 23
(3) 254 271 364 454 576 0
(1) Operating Income before Depr,154,167,214,290,444
(1.1) buffer length = 52
(2) Operating Income before Depr
(2.2) buffer length = 21
(3) 154 167 214 290 444 0
(1) Depreciation and Amortization,25,31,38,52,70
(1.1) buffer length = 46
(2) Depreciation and Amortization
(2.2) buffer length = 16
(3) 25 31 38 52 70 0
(1) Operating Profit,129,136,176,238,374
(1.1) buffer length = 40
(2) Operating Profit
(2.2) buffer length = 21
(3) 129 136 176 238 374 0
(1) Interest Expense,4,3,3,1,4
(1.1) buffer length = 28
(2) Interest Expense
(2.2) buffer length = 11
(3) 4 3 3 1 4 0
(1) Other Gains and Losses,0,7,10,0,-1
(1.1) buffer length = 36
(2) Other Gains and Losses
(2.2) buffer length = 13
(3) 0 7 10 0 -1 0
(1) Pretax Income,125,126,163,237,371
(1.1) buffer length = 37
(2) Pretax Income
(2.2) buffer length = 21
(3) 125 126 163 237 371 0
(1) Income Tax Expense,55,52,65,92,141
(1.1) buffer length = 36
(2) Income Tax Expense
(2.2) buffer length = 17
(3) 55 52 65 92 141 0
(1) Net Income,70,74,98,145,230
(1.1) buffer length = 31
(2) Net Income
(2.2) buffer length = 18
(3) 70 74 98 145 230 0
Something went wrong with the provided file
******hex******
49 6E 63 6F 6D 65 20 53 74 61 74 65 6D 65 6E 74
2C 32 30 31 31 2C 32 30 31 32 2C 32 30 31 33 2C
32 30 31 34 2C 32 30 31 35 0D 0A 53 61 6C 65 73
2C 31 30 36 32 2C 31 32 35 32 2C 31 35 38 37 2C
31 39 33 34 2C 32 35 31 39 0D 0A 43 6F 73 74 20
6F 66 20 47 6F 6F 64 73 20 53 6F 6C 64 2C 36 35
34 2C 38 31 34 2C 31 30 30 39 2C 31 31 39 30 2C
31 34 39 39 0D 0A 20 20 47 72 6F 73 73 20 50 72
6F 66 69 74 2C 34 30 38 2C 34 33 38 2C 35 37 38
2C 37 34 34 2C 31 30 32 30 0D 0A 22 53 65 6C 6C
69 6E 67 2C 20 47 65 6E 65 72 61 6C 2C 20 61 6E
64 20 41 64 6D 69 6E 20 45 78 70 22 2C 32 35 34
2C 32 37 31 2C 33 36 34 2C 34 35 34 2C 35 37 36
0D 0A 20 20 4F 70 65 72 61 74 69 6E 67 20 49 6E
63 6F 6D 65 20 62 65 66 6F 72 65 20 44 65 70 72
2C 31 35 34 2C 31 36 37 2C 32 31 34 2C 32 39 30
2C 34 34 34 0D 0A 44 65 70 72 65 63 69 61 74 69
6F 6E 20 61 6E 64 20 41 6D 6F 72 74 69 7A 61 74
69 6F 6E 2C 32 35 2C 33 31 2C 33 38 2C 35 32 2C
37 30 0D 0A 20 20 4F 70 65 72 61 74 69 6E 67 20
50 72 6F 66 69 74 2C 31 32 39 2C 31 33 36 2C 31
37 36 2C 32 33 38 2C 33 37 34 0D 0A 49 6E 74 65
72 65 73 74 20 45 78 70 65 6E 73 65 2C 34 2C 33
2C 33 2C 31 2C 34 0D 0A 4F 74 68 65 72 20 47 61
69 6E 73 20 61 6E 64 20 4C 6F 73 73 65 73 2C 30
2C 37 2C 31 30 2C 30 2C 2D 31 0D 0A 20 20 50 72
65 74 61 78 20 49 6E 63 6F 6D 65 2C 31 32 35 2C
31 32 36 2C 31 36 33 2C 32 33 37 2C 33 37 31 0D
0A 49 6E 63 6F 6D 65 20 54 61 78 20 45 78 70 65
6E 73 65 2C 35 35 2C 35 32 2C 36 35 2C 39 32 2C
31 34 31 0D 0A 20 20 4E 65 74 20 49 6E 63 6F 6D
65 2C 37 30 2C 37 34 2C 39 38 2C 31 34 35 2C 32
33 30 0D 0A
(3) My file:
******csv input with a vivd trailing comma******
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,
******program output******
(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
(1) Sales,1062,1252,1587,1934,2519,
(1.1) buffer length = 32
(2) Sales
(2.2) buffer length = 26
(3) 1062 1252 1587 1934 2519 0
(1) Cost of Goods Sold,654,814,1009,1190,1499,
(1.1) buffer length = 44
(2) Cost of Goods Sold
(2.2) buffer length = 25
(3) 654 814 1009 1190 1499 0 0
(1) Gross Profit,408,438,578,744,1020,
(1.1) buffer length = 38
(2) Gross Profit
(2.2) buffer length = 23
(3) 408 438 578 744 1020 0 0
(1) SG&A,254,271,364,454,576,
(1.1) buffer length = 27
(2) SG&A
(2.2) buffer length = 22
(3) 254 271 364 454 576 0 0
(1) Operating Income before Depr,154,167,214,290,444,
(1.1) buffer length = 53
(2) Operating Income before Depr
(2.2) buffer length = 22
(3) 154 167 214 290 444 0 0
(1) Depreciation and Amortization,25,31,38,52,70,
(1.1) buffer length = 47
(2) Depreciation and Amortization
(2.2) buffer length = 17
(3) 25 31 38 52 70 0 0
(1) Operating Profit,129,136,176,238,374,
(1.1) buffer length = 41
(2) Operating Profit
(2.2) buffer length = 22
(3) 129 136 176 238 374 0 0
(1) Interest Expense,4,3,3,1,4,
(1.1) buffer length = 29
(2) Interest Expense
(2.2) buffer length = 12
(3) 4 3 3 1 4 0 0
(1) Other Gains and Losses,0,7,10,0,-1,
(1.1) buffer length = 37
(2) Other Gains and Losses
(2.2) buffer length = 14
(3) 0 7 10 0 -1 0 0
(1) Pretax Income,125,126,163,237,371,
(1.1) buffer length = 38
(2) Pretax Income
(2.2) buffer length = 22
(3) 125 126 163 237 371 0 0
(1) Income Tax Expense,55,52,65,92,141,
(1.1) buffer length = 37
(2) Income Tax Expense
(2.2) buffer length = 18
(3) 55 52 65 92 141 0 0
(1) Net Income,70,74,98,145,230,
(1.1) buffer length = 32
(2) Net Income
(2.2) buffer length = 19
(3) 70 74 98 145 230 0 0
Something went wrong with the provided file
******hex******
59 65 61 72 73 2C 32 30 31 31 2C 32 30 31 32 2C
32 30 31 33 2C 32 30 31 34 2C 32 30 31 35 2C 0A
53 61 6C 65 73 2C 31 30 36 32 2C 31 32 35 32 2C
31 35 38 37 2C 31 39 33 34 2C 32 35 31 39 2C 0A
43 6F 73 74 20 6F 66 20 47 6F 6F 64 73 20 53 6F
6C 64 2C 36 35 34 2C 38 31 34 2C 31 30 30 39 2C
31 31 39 30 2C 31 34 39 39 2C 0D 0A 20 20 47 72
6F 73 73 20 50 72 6F 66 69 74 2C 34 30 38 2C 34
33 38 2C 35 37 38 2C 37 34 34 2C 31 30 32 30 2C
0D 0A 53 47 26 41 2C 32 35 34 2C 32 37 31 2C 33
36 34 2C 34 35 34 2C 35 37 36 2C 0D 0A 20 20 4F
70 65 72 61 74 69 6E 67 20 49 6E 63 6F 6D 65 20
62 65 66 6F 72 65 20 44 65 70 72 2C 31 35 34 2C
31 36 37 2C 32 31 34 2C 32 39 30 2C 34 34 34 2C
0D 0A 44 65 70 72 65 63 69 61 74 69 6F 6E 20 61
6E 64 20 41 6D 6F 72 74 69 7A 61 74 69 6F 6E 2C
32 35 2C 33 31 2C 33 38 2C 35 32 2C 37 30 2C 0D
0A 20 20 4F 70 65 72 61 74 69 6E 67 20 50 72 6F
66 69 74 2C 31 32 39 2C 31 33 36 2C 31 37 36 2C
32 33 38 2C 33 37 34 2C 0D 0A 49 6E 74 65 72 65
73 74 20 45 78 70 65 6E 73 65 2C 34 2C 33 2C 33
2C 31 2C 34 2C 0D 0A 4F 74 68 65 72 20 47 61 69
6E 73 20 61 6E 64 20 4C 6F 73 73 65 73 2C 30 2C
37 2C 31 30 2C 30 2C 2D 31 2C 0D 0A 20 20 50 72
65 74 61 78 20 49 6E 63 6F 6D 65 2C 31 32 35 2C
31 32 36 2C 31 36 33 2C 32 33 37 2C 33 37 31 2C
0D 0A 49 6E 63 6F 6D 65 20 54 61 78 20 45 78 70
65 6E 73 65 2C 35 35 2C 35 32 2C 36 35 2C 39 32
2C 31 34 31 2C 0D 0A 20 20 4E 65 74 20 49 6E 63
6F 6D 65 2C 37 30 2C 37 34 2C 39 38 2C 31 34 35
2C 32 33 30 2C 0D 0A
[toc] | [prev] | [next] | [standalone]
Page 1 of 4 [1] 2 3 4 Next page →
Back to top | Article view | comp.lang.c
csiph-web