By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Looking for a C program to parse CSV

P: n/a
I have an excel spreadsheet that I need to parse. I was thinking of saving
this as a CSV file. And then reading the file using C. The actual in EXCEL
looks like:
a,b a"b a","b a,",b

In CSV format looks like:
"a,b","a""b","a"",""b","a,"",b"

Does anybody have suggestions or have C program based code to parse CSV.
Please reply to the message board itself. I do not wish to get spam.

Nov 15 '05 #1
Share this Question
Share on Google+
46 Replies


P: n/a
vvk4 <vv**@nospam.mail.com> wrote:
Does anybody have suggestions or have C program based code to parse CSV.
Please reply to the message board itself. I do not wish to get spam.


Read the strings from the file with fgets(), then parse the strings
with strtok() and do whatever you like with them.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #2

P: n/a
vvk4 wrote:
I have an excel spreadsheet that I need to parse. I was thinking of saving
this as a CSV file. And then reading the file using C. The actual in EXCEL
looks like:
a,b a"b a","b a,",b

In CSV format looks like:
"a,b","a""b","a"",""b","a,"",b"
Yes, this is a sensible approach.
Does anybody have suggestions or have C program based code to parse CSV.
Yes, write a program in standard C and post here with any problems. This
is not a sources wanted group, it is a group for discussing the language.
Please reply to the message board itself.
This is not a message board, it is a news group. The fact that you use a
web interface does not change this, and most users do *not* use a web
interface.
I do not wish to get spam.


We don't wish to get off topic posts. Did you read the FAQ, welcome
message, and a few days worth of posts before posting here? I think not.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #3

P: n/a
In article <di**********@chessie.cirr.com>,
Christopher Benson-Manica <at***@nospam.cyberspace.org> wrote:


vvk4 <vv**@nospam.mail.com> wrote:
Does anybody have suggestions or have C program based code to parse CSV.
Please reply to the message board itself. I do not wish to get spam.


Read the strings from the file with fgets(), then parse the strings
with strtok() and do whatever you like with them.


I think this is bad advice for the kind of file the original poster had
in mind. strtok() doesn't understand quotes, plus it treats runs of
separators as a single unit so empty fields in a CSV file can be
inadvertently skipped. You can use strtok, but you'll have to do quite
some work to overcome its limitations.

Better advice might be to just look at each character in the string
left to right and keep track of whether you're in a quoted string or
not. When you reach an unquoted comma, that's a field separator.
That, combined with turning "" into " inside of quotes would be
sufficient and probably simpler than strtok().

Along the way, one might learn things about parsing, which is perhaps
more interesting than the code itself.
Nov 15 '05 #4

P: n/a
Anonymous 7843 <an******@example.com> wrote:
Better advice might be to just look at each character in the string
left to right and keep track of whether you're in a quoted string or
not. When you reach an unquoted comma, that's a field separator.
That, combined with turning "" into " inside of quotes would be
sufficient and probably simpler than strtok().


I had forgotten about commas in the quoted fields, but OP didn't
specify what quality of suggestions he or she was looking for :-)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #5

P: n/a
Here is a C program that needs to be debugged. It will read first 999
characters of a line.
#include <stdio.h>
#include <string.h>
void main()
{
FILE *myfile;
char line1[1000];
char line2[1000];
char line3[1000]; /* Each field in the line */
char *stptr;
int flag = 0;
int idx = 0;
int lcount = 0; /* Loop counter for debugging */
myfile = fopen("alive.txt","r");
if(!myfile)
{
puts("Some kind of file error!");
exit(0);
}

/* Get a line from file */
while (fgets(line1,999,myfile) != NULL)
{
strcpy(line2,line1);
stptr = line2;

/* start going character by character thro the line */
while (*stptr != '\0')
{ lcount++;
printf("%d",lcount);
/* If field begins with " */
if (*stptr == '"')
{ int flag = 0;
while (flag = 0)
{ idx = 0;
stptr++;
/* Find corresponding closing " */
while (*stptr != '"')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
stptr++;
idx++;
if (*stptr == ',' || *stptr == '\0')
{
line3[idx] = '\0';
printf("%s",line3);
flag = 1;
}
else if (*stptr == '"')
{ line3[idx] = *stptr;
stptr++;
idx++;
}
}
}
else
{ idx = 0;
while (*stptr != '\0' && *stptr != ',')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
line3[idx] = '\0';
printf("%s",line3);
}
if (*stptr != '\0' && *stptr == ',')
stptr++;
strcpy(line2,stptr);
stptr = line2;
}
}
fclose(myfile);
}
Nov 15 '05 #6

P: n/a
Here is the program. It needs debugging. It is looping.
#include <stdio.h>
#include <string.h>
void main()
{
FILE *myfile;
char line1[1000];
char line2[1000];
char line3[1000]; /* Each field in the line */
char *stptr;
int flag = 0;
int idx = 0;
int lcount = 0; /* Loop counter for debugging */
myfile = fopen("alive.txt","r");
if(!myfile)
{
puts("Some kind of file error!");
exit(0);
}

/* Get a line from file */
while (fgets(line1,999,myfile) != NULL)
{
strcpy(line2,line1);
stptr = line2;

/* start going character by character thro the line */
while (*stptr != '\0')
{ lcount++;
printf("%d",lcount);
/* If field begins with " */
if (*stptr == '"')
{ int flag = 0;
while (flag = 0)
{ idx = 0;
stptr++;
/* Find corresponding closing " */
while (*stptr != '"')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
stptr++;
idx++;
if (*stptr == ',' || *stptr == '\0')
{
line3[idx] = '\0';
printf("%s",line3);
flag = 1;
}
else if (*stptr == '"')
{ line3[idx] = *stptr;
stptr++;
idx++;
}
}
}
else
{ idx = 0;
while (*stptr != '\0' && *stptr != ',')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
line3[idx] = '\0';
printf("%s",line3);
}
if (*stptr != '\0' && *stptr == ',')
stptr++;
strcpy(line2,stptr);
stptr = line2;
}
}
fclose(myfile);
}
Nov 15 '05 #7

P: n/a
vvk4 wrote:
Here is a C program that needs to be debugged. It will read first 999
characters of a line.
Your code (preserved below) does far too much. Here is a cut-down
version that may provide you with a place to start in properly designing
your program:

#include <stdio.h>
#include <stdlib.h>

#define LBUFSIZ 1000

int main(void)
{
FILE *myfile;
char input_line[LBUFSIZ];
char token[LBUFSIZ];
char *cptr, *tptr;

if (!(myfile = fopen("alive.txt", "r"))) {
fprintf(stderr, "Could not open \"alive.txt\" for reading\n");
exit(EXIT_FAILURE);
}

/* Get a line from file */
while (fgets(input_line, sizeof input_line, myfile))
for (cptr = input_line; *cptr;) {
tptr = token;
*tptr = 0;
if (*cptr == '"') {
for (tptr = token, cptr++; *cptr && *cptr != '"';)
*tptr++ = *cptr++;
*tptr = 0;
}
else {
for (tptr = token; *cptr && *cptr != ',';)
*tptr++ = *cptr++;
*tptr = 0;
}
if (*cptr && *cptr == ',')
cptr++;
if (*token)
printf("%s", token);
}
putchar('\n');
fclose(myfile);
}

[OP's code] #include <stdio.h>
#include <string.h>
void main()
{
FILE *myfile;
char line1[1000];
char line2[1000];
char line3[1000]; /* Each field in the line */
char *stptr;
int flag = 0;
int idx = 0;
int lcount = 0; /* Loop counter for debugging */
myfile = fopen("alive.txt","r");
if(!myfile)
{
puts("Some kind of file error!");
exit(0);
}

/* Get a line from file */
while (fgets(line1,999,myfile) != NULL)
{
strcpy(line2,line1);
stptr = line2;

/* start going character by character thro the line */
while (*stptr != '\0')
{ lcount++;
printf("%d",lcount);
/* If field begins with " */
if (*stptr == '"')
{ int flag = 0;
while (flag = 0)
{ idx = 0;
stptr++;
/* Find corresponding closing " */
while (*stptr != '"')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
stptr++;
idx++;
if (*stptr == ',' || *stptr == '\0')
{
line3[idx] = '\0';
printf("%s",line3);
flag = 1;
}
else if (*stptr == '"')
{ line3[idx] = *stptr;
stptr++;
idx++;
}
}
}
else
{ idx = 0;
while (*stptr != '\0' && *stptr != ',')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
line3[idx] = '\0';
printf("%s",line3);
}
if (*stptr != '\0' && *stptr == ',')
stptr++;
strcpy(line2,stptr);
stptr = line2;
}
}
fclose(myfile);
}

Nov 15 '05 #8

P: n/a
Here is the program that correctly reads a CSV FILE and spits the value
each cell. I have numbered each cell just for verification. Thanks to
Martin and everybody else for suggestions. You may be able to condense
this further.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define LBUFSIZ 1000

int main()
{
FILE *myfile;
char line1[LBUFSIZ];
char line2[LBUFSIZ];
char line3[LBUFSIZ]; /* Each field in the line */
char *stptr;
int flag = 0;
int idx = 0;
int lcount = 0; /* Cell Seperator */

if (!(myfile = fopen("alive.txt", "r")))
{
fprintf(stderr, "Could not open \"alive.txt\" for reading\n");
exit(EXIT_FAILURE);
}

/* Get a line from file */
while (fgets(line1,sizeof line1,myfile) != NULL)
{ lcount = 0;
strcpy(line2,line1);
stptr = line2;

/* start going character by character thro the line */
while (*stptr != '\0')
{ lcount++;
printf("%d",lcount);
/* If field begins with " */
if (*stptr == '"')
{
int flag = 0;
idx = 0;
while (flag == 0)
{

stptr++;
/* Find corresponding closing " */
while (*stptr != '"')
{ line3[idx] = *stptr;
idx++;
stptr++;
}

stptr++;
if (*stptr != '\0' && *stptr == ',')
{

line3[idx] = '\0';
printf("%s",line3);
flag = 1;
}
else if (*stptr != '\0' && *stptr == '"')
{ line3[idx] = *stptr;
idx++;
}
else
{

line3[idx] = '\0';
printf("%s",line3);
flag = 1;
}
}
}
else
{ idx = 0;
while (*stptr != '\0' && *stptr != ',')
{ line3[idx] = *stptr;
idx++;
stptr++;
}
line3[idx] = '\0';
printf("%s",line3);
}
if (*stptr != '\0' && *stptr == ',')
stptr++;
strcpy(line2,stptr);
stptr = line2;
}
putchar('\n');
}
fclose(myfile);
}
Nov 15 '05 #9

P: n/a
In article <di**********@chessie.cirr.com>,
Christopher Benson-Manica <at***@nospam.cyberspace.org> wrote:
Anonymous 7843 <an******@example.com> wrote:
Better advice might be to just look at each character in the string
left to right and keep track of whether you're in a quoted string or
not. When you reach an unquoted comma, that's a field separator.
That, combined with turning "" into " inside of quotes would be
sufficient and probably simpler than strtok().


I had forgotten about commas in the quoted fields, but OP didn't
specify what quality of suggestions he or she was looking for :-)


It's not like they listen to our suggestions about the quality
of questions...
Nov 15 '05 #10

P: n/a
vvk4 <vv**@nospam.mail.com> wrote:
Here is the program. It needs debugging. It is looping.
It is proper Usenet etiquette to include the text you are replying to.
To do this using Google groups, please follow the instructions below,
penned by Keith Thompson:

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Flash Gordon wrote (context restored):
We don't wish to get off topic posts. Did you read the FAQ, welcome
message, and a few days worth of posts before posting here? I think
not.


Did you understand the import of these words? Get thee to the FAQ and
welcome message.

http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
#include <stdio.h>
#include <string.h> void main()
This is how we know you didn't read the FAQ. void main() is patently
wrong.
{
FILE *myfile;
char line1[1000];
char line2[1000];
char line3[1000]; /* Each field in the line */
char *stptr;
int flag = 0;
int idx = 0;
int lcount = 0; /* Loop counter for debugging */
myfile = fopen("alive.txt","r");
if(!myfile)
{
puts("Some kind of file error!");
exit(0);
#include <stdlib.h>

exit( EXIT_FAILURE );

Zero denotes success. A file error is not success.
} /* Get a line from file */
while (fgets(line1,999,myfile) != NULL)


Better is

while( fgets(line1,sizeof line1,myfile) != NULL )

If you change the size of line1, this version changes with it. Yours
does not.

The rest of your code is more complicated than it has to be. Think
about using strcspn() to find the commas and double quotes more
easily.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #11

P: n/a
Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
vvk4 <vv**@nospam.mail.com> wrote:
Here is the program. It needs debugging. It is looping.


It is proper Usenet etiquette to include the text you are replying to.


A quibble: It is proper Usenet etiquette to include *the relevant
portions of* the text you are replying to. Sometimes that's the
entire article; more often it isn't.

(If I were being really pedantic I would have written "to which you
are replying".)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #12

P: n/a
Keith Thompson wrote:

(If I were being really pedantic I would have written "to which you
are replying".)


Why is that?


Brian
Nov 15 '05 #13

P: n/a

"Default User" <de***********@yahoo.com> wrote in message
news:3q************@individual.net...
Keith Thompson wrote:

(If I were being really pedantic I would have written "to which you
are replying".)


Why is that?


It's because it is incorrect English grammar to
end a sentence with a preposition (e.g.
"... which you are replying to."

BTW I once ended a sentence with a proposition,
and I'm still serving my sentence. (Just kidding,
she's great.) :-)

-Mike
Nov 15 '05 #14

P: n/a
Mike Wahler wrote:
"Default User" <de***********@yahoo.com> wrote in message
news:3q************@individual.net...
Keith Thompson wrote:
(If I were being really pedantic I would have written "to which you
are replying".)
Why is that?

It's because it is incorrect English grammar to
end a sentence with a preposition (e.g.
"... which you are replying to."

Off-topic, but before someone starts quoting Churchill: most people feel
free to ignore this rather artificial rule. See
http://www.grammartips.homestead.com/prepositions1.html, just one site
of many who explain this. See also http://en.wikipedia.org/wiki/Preposition.

Fact is, people adhere to this rule because they adhere to this rule, so
violating it is wrong because they "just know" it's wrong. It has little
to do with "live" English grammar.

"It is proper Usenet etiquette to include the text you are replying to"
is a fine English sentence. Ask anyone who's not a grammarian, then ask
the grammarians why it shouldn't be. :-)
BTW I once ended a sentence with a proposition,
and I'm still serving my sentence. (Just kidding,
she's great.) :-)

The site I linked to even uses your pun, so it can't be coincidence. :-)

S.
Nov 15 '05 #15

P: n/a
Mike Wahler wrote:

"Default User" <de***********@yahoo.com> wrote in message
news:3q************@individual.net...
Keith Thompson wrote:

(If I were being really pedantic I would have written "to which
you are replying".)


Why is that?


It's because it is incorrect English grammar to
end a sentence with a preposition (e.g.
"... which you are replying to."

No, it's not. Nor is it incorrect grammar to split the infinitive, the
other great urban legend of English grammar.

Brian
Nov 15 '05 #16

P: n/a
Keith Thompson <ks***@mib.org> wrote:
A quibble: It is proper Usenet etiquette to include *the relevant
portions of* the text you are replying to. Sometimes that's the
entire article; more often it isn't.


If the only quibble you had with my post was that I included too much
quoted text (I did trim some, but perhaps not adequately), then I'm
happy with it.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #17

P: n/a
Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
Keith Thompson <ks***@mib.org> wrote:
A quibble: It is proper Usenet etiquette to include *the relevant
portions of* the text you are replying to. Sometimes that's the
entire article; more often it isn't.


If the only quibble you had with my post was that I included too much
quoted text (I did trim some, but perhaps not adequately), then I'm
happy with it.


My quibble was that you didn't mention the need to trim text, not that
you failed to do so yourself. Your statement was:

] It is proper Usenet etiquette to include the text you are replying to.

Of course, if "the text you are replying to" referred only to the
relevant text, rather than the entire article, then I have hardly any
quibble at all.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #18

P: n/a
On Sat, 08 Oct 2005 01:02:51 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
(of the rule of english grammar that you may not end a sentence with a
preposition)
Fact is, people adhere to this rule because they adhere to this rule, so
violating it is wrong because they "just know" it's wrong. It has little
to do with "live" English grammar.


If you can't see how bogus this argument is, I pity you. One might as
well say that slang is proper engish, innit like, y'know?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #19

P: n/a
Mark McIntyre wrote:
On Sat, 08 Oct 2005 01:02:51 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
(of the rule of english grammar that you may not end a sentence with a
preposition)

Fact is, people adhere to this rule because they adhere to this rule, so
violating it is wrong because they "just know" it's wrong. It has little
to do with "live" English grammar.

If you can't see how bogus this argument is, I pity you. One might as
well say that slang is proper engish, innit like, y'know?


There is a world of difference between using slang in contexts where
it's not appropriate and ending your sentences with a preposition. So no
-- one might not "as well" say that.

If you're looking for an absolute stance on what makes language use
right and wrong, however, I have none to offer you, and wouldn't trust
people who claim they do. I was merely pointing out that I cannot agree
with people who judge that ending a sentence with a preposition is
wrong, because they have nothing more concrete to offer than "because we
say so".

That argument is equally bogus: we should speak and write only as
grammarians tell us to, because they know how the language works and the
majority of its speakers don't. That's not how natural language works,
no matter how hard you wish it worked that way.

Clearly the truth is in the middle -- grammar has rules, but rules
evolve from use. In this case, the argument is that the rule being
applied never evolved from anything but the imagination of language
lawyers, and while that may work for a programming language, it doesn't
work for English.

But let's not drag comp.lang.c into a discussion of prescriptivist vs.
descriptivist grammar. In C, it's all much simpler: consult the standard
and it will tell you.

S.
Nov 15 '05 #20

P: n/a
On Sat, 08 Oct 2005 22:05:03 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
There is a world of difference between using slang in contexts where
it's not appropriate and ending your sentences with a preposition. So no
-- one might not "as well" say that.
Obviously I disagree. It may be a common usage in certain parts of the
world, but that doesn't make it correct grammar and more than slang
usage is correct.
If you're looking for an absolute stance on what makes language use
right and wrong, however, I have none to offer you, and wouldn't trust
people who claim they do.
*shrug*.
I was merely pointing out that I cannot agree
with people who judge that ending a sentence with a preposition is
wrong, because they have nothing more concrete to offer than "because we
say so".


And what, pray, are any rules of grammar but "because thats how it
is"? Be sensible.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #21

P: n/a
Mark McIntyre wrote:
On Sat, 08 Oct 2005 01:02:51 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
(of the rule of english grammar that you may not end a sentence with a
preposition)
Fact is, people adhere to this rule because they adhere to this
rule, so violating it is wrong because they "just know" it's wrong.
It has little to do with "live" English grammar.


If you can't see how bogus this argument is, I pity you. One might as
well say that slang is proper engish, innit like, y'know?


You're wrong. The bit about prepositions was invented out of whole
cloth by certain self-appointed language purists. It never has been a
violation of grammar to formulate sentences that way.

Here's the relevant bit from the alt.usage.english FAQ:

Fowler and nearly every other respected prescriptivist see
NOTHING wrong with ending a clause with a preposition; Fowler
calls it a "superstition". ("Never end a sentence with a
preposition" is how the superstition is usually stated, although it
would "naturally" extend to any placement of a preposition later
than the noun or pronoun it governs.) Indeed, Fowler considers "a
good land to live in" grammatically superior to "a good land in
which to live", since one cannot say *"a good land which to
inhabit".

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Nov 15 '05 #22

P: n/a
Mark McIntyre wrote:
On Sat, 08 Oct 2005 22:05:03 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:

There is a world of difference between using slang in contexts where
it's not appropriate and ending your sentences with a preposition. So no
-- one might not "as well" say that.

Obviously I disagree. It may be a common usage in certain parts of the
world, but that doesn't make it correct grammar and more than slang
usage is correct.

Well, this is where the chips come down and we both confess that we have
no actual clue as to how common or uncommon ending your sentence with a
preposition is. Certain parts of the world for sure, but which parts for
certain?

Just because you "know" it's wrong, and I "know" it's not, doesn't make
either of us right, does it? We'd need to hunt down independent sources
and get our facts straight, rather than making appeals to authority --
so we'll probably have to agree to disagree on the particular issue, and
when I'm around you I'll have to be careful about what I end my
sentences with.

Try to reformulate that last sentence to comply with the vaunted rule,
by the way. It's instructive. :-)

<snip>
I was merely pointing out that I cannot agree
with people who judge that ending a sentence with a preposition is
wrong, because they have nothing more concrete to offer than "because we
say so".

And what, pray, are any rules of grammar but "because thats how it
is"? Be sensible.


Linguistics is a science. That is, we can study language, formulate
hypotheses, and test these. The difference between "because we say so"
and "because that's how it is" should be immediately obvious now.
Whether a grammatical rule is "real" is something that can be made more
or less plausible by observing actual application.

What complicates the issue enormously, however, and what is at the heart
of our disagreement, is the fact that language is man-made (some would
claim wholly, most only partially). In a sense, language is "whatever we
make of it". So in that sense, you're certainly right. If you say
sentences should not end with prepositions because that's ungrammatical,
who am I to say that's a silly, arbitrary rule? So is declining
pronouns. Yet someone who refuses to decline is criticized for poor
grammar, and rightly so. The rules are not imaginary or a free-for-all;
there's right and wrong.

So who gets to decide right and wrong? If I tell everyone not to use
"henceforth" anymore because it's an outdated construction that can
easily be replaced with the catchier "from that point on", and they
actually listen to me, then henceforth it's no longer proper English --
archaic at best.

But of course this almost never happens. Instead language mutates in the
wild, according to ill-understood processes that have very little to do
with rational thought, and all the more with how our language instincts
work. "Henceforth" acquires a mothball smell because people simply stop
using it, or use it only in certain contexts.

The rules of grammar as expounded by books, grammarians and classrooms
are at any time a compromise between what is actually spoken and what is
believed to be spoken; what of this is proper, and what not. The rules
as written down are invariably lagging behind actual usage -- mind you,
I say "lagging behind", implying that the rules are eventually adapted
to accommodate live usage, not the other way around. This is because
those who teach language (the part that can be taught) are always the
minority compared to those who use language, both in numbers and
influence. And in language, sad to say for the teachers, tyranny of the
majority does apply.

A change of language always starts out small. When one person does it,
it's wrong. When it's picked up by others, it's slang, or dialect. As it
grows it may become "mainstream", possibly still frowned upon or
"considered informal" by more conservative elements. This non-state can
persist for a very long time, even when everybody is doing it except
those who insist it's wrong because they remember a time when not
everyone was doing it. Eventually they succumb, and the official record
is updated to reflect actual use. This process is much faster for new
words than it is for changes in grammar, but the same principles apply.

Now, what does all this have to do with ending your sentences in a
preposition?! Simple: I believe this particular rule not to be part of
live English; English as spoken by well-intended people who respect a
consensus vision on what proper English should be, and who appreciate
clear communication (an elitist and snobby description, but you get my
drift). It's something cooked up by grammarians because they had visions
of how the language ought to look that had nothing to do with how it was
used.

In doing so, they did not *add* to the man-made construct called
English, they impoverished it by outlawing something for no other reason
than that it did not match their vision of English -- not because anyone
somehow failed to understand these constructions correctly, not because
clear communication was threatened. Grammarians are as free to try and
change the language as anyone else -- and everyone is equally free to
ignore them. The measure of a rule of grammar is how well it is
followed, not how sensible it is to its creators. This is a scary
prospect to those who believe that language is something we wholly
control by application of reason and sensibility, but the fact is, we don't.

I'm not trying to win an argument, just explaining where I'm coming
from. If I have to be any *more* sensible I'll have to invite you to
come over to my place for coffee or tea and we'll talk about this until
we're both blue in the face, but for now let's spare the other folks in
this ng, OK? :-) I respect your belief that not ending your sentences in
a preposition is a hallmark of proper grammar, though I disagree, and
will continue to merrily end my sentences in prepositions whenever I
think it's appropriate; the argument of who is right can be postponed.

S.
Nov 15 '05 #23

P: n/a
On 8 Oct 2005 22:54:34 GMT, in comp.lang.c , "Default User"
<de***********@yahoo.com> wrote:
You're wrong.
Obviously, I disagree. Call me a language purist if you like.
The bit about prepositions was invented out of whole
cloth by certain self-appointed language purists.
Which is of course how absolutely any 'rule of grammar' was
'invented'.
Here's the relevant bit from the alt.usage.english FAQ:


Last time I checked, usenet, especially the alt hierarchy, was not
considered a reliable source of information !

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #24

P: n/a
On Sun, 09 Oct 2005 02:09:41 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
and
when I'm around you I'll have to be careful about what I end my
sentences with. Try to reformulate that last sentence to comply with the vaunted rule,
by the way. It's instructive. :-)


I'll just try the last clause if its ok:

"You'll have to be careful with what you end your sentences."
or
"You'll have to be careful with which word types you end your
sentences."

Golly that was tricky. In fact the 2nd is probably slightly clearer
than the original...
And what, pray, are any rules of grammar but "because thats how it
is"? Be sensible.


Linguistics is a science.


ROFL.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #25

P: n/a
"Default User" <de***********@yahoo.com> writes:
[...]
Here's the relevant bit from the alt.usage.english FAQ:


Speaking of alt.usage.english, it does exist, and is an appropriate
place for this discussion. comp.lang.c is not.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #26

P: n/a
Mark McIntyre wrote:
On Sun, 09 Oct 2005 02:09:41 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:

and
when I'm around you I'll have to be careful about what I end my
sentences with.
Try to reformulate that last sentence to comply with the vaunted rule,
by the way. It's instructive. :-)

I'll just try the last clause if its ok:

"You'll have to be careful with what you end your sentences."


Nope, sorry. That would have to be "careful about with what you end your
sentences". You can't remove "about" here, because "being careful with"
leaves "what you end your sentences" as a phrase, which isn't
grammatical; the verb phrase is "to end with".

I'll just stick that "with" at the end, thank you.
or
"You'll have to be careful with which word types you end your
sentences."

Golly that was tricky. In fact the 2nd is probably slightly clearer
than the original...

Hmm, yeah. Like anyone who's not a programmer would mention "word
types". :-)
And what, pray, are any rules of grammar but "because thats how it
is"? Be sensible.


Linguistics is a science.

ROFL.


That's one way to end a thread, I guess. If you like, I can amend it to
"some parts of linguistics can be approached scientifically".
Nevertheless, I'm glad I amuse you.

S.
Nov 15 '05 #27

P: n/a

"Skarmander" <in*****@dontmailme.com> wrote
and when I'm around you I'll have to be careful about what I end my
sentences with.

Try to reformulate that last sentence to comply with the vaunted rule, by
the way. It's instructive. :-)

and when I'm around you I'll have to be careful about that with which I end
my sentences.

I agree. This is hopelessly old-fashioned.

<On T>
You can have compileable gibberish in English as well as in C.
</On T>
Nov 15 '05 #28

P: n/a
Mark McIntyre wrote:
On 8 Oct 2005 22:54:34 GMT, in comp.lang.c , "Default User"
<de***********@yahoo.com> wrote:
You're wrong.


Obviously, I disagree. Call me a language purist if you like.


I will not. You aren't a purist, you're incorrect. A purist would
promulgate actual rules not bogus ones.
Here's the relevant bit from the alt.usage.english FAQ:


Last time I checked, usenet, especially the alt hierarchy, was not
considered a reliable source of information !


Pretty odd statement from coming from a denizen of a usenet group that
thinks its musings on a language should be taken seriously, and that
its FAQ should be used a reference for that language.

However, as Keith has pointed out, this isn't the place to debate it.
If you'd like to continue it over to alt.usage.english, be my guest.

Brian
Nov 15 '05 #29

P: n/a
Skarmander said:
Mike Wahler wrote:

It's because it is incorrect English grammar to
end a sentence with a preposition (e.g.
"... which you are replying to."

Off-topic, but before someone starts quoting Churchill:


Darn it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/2005
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 15 '05 #30

P: n/a
In article <di**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:

Skarmander said:
Mike Wahler wrote:

It's because it is incorrect English grammar to
end a sentence with a preposition (e.g.
"... which you are replying to."

Off-topic, but before someone starts quoting Churchill:


Darn it.


Ah, but a quote can be pointed to:

http://www.wsu.edu/~brians/errors/churchill.html

It doesn't have the variation I remember (abomination), but it has
a better one (bloody nonsense) that is now the one I am most fond of.
Nov 15 '05 #31

P: n/a
"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:j1********************************@4ax.com...
On 8 Oct 2005 22:54:34 GMT, in comp.lang.c , "Default User"
<de***********@yahoo.com> wrote:
You're wrong.


Obviously, I disagree. Call me a language purist if you like.
The bit about prepositions was invented out of whole
cloth by certain self-appointed language purists.


Which is of course how absolutely any 'rule of grammar' was
'invented'.


But the rule of never starting a sentence with a conjunction is still
valid, isn't it? And, there are cases when the convoluted sentences are
made much clearer by not using convolutions with which to use to avoid
saying.
Here's the relevant bit from the alt.usage.english FAQ:


Last time I checked, usenet, especially the alt hierarchy, was not
considered a reliable source of information !


But, it's that with which we are stuck. No body read BOOKS anymore.

My pet peeve are those who don't know when to use whom. Everybody get
the difference between her and she, him and he, etc. but are baffled by
the who and whom connection, even though it is identical usage. I
explain it this way: if you could use he then use who, if you would use
him use whom; he = who, him = whom (notice the m at the end).
"You went with him?" = "You went with whom?" NOT "You went with he?" =
"You went with who?"
"He and I went..." = "Who went ..."

Seems simple to me.

--
Mabden
Nov 15 '05 #32

P: n/a
Mark McIntyre wrote:
On Sun, 09 Oct 2005 02:09:41 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
and
when I'm around you I'll have to be careful about what I end my
sentences with.

Try to reformulate that last sentence to comply with the vaunted rule,
by the way. It's instructive. :-)


I'll just try the last clause if its ok:

"You'll have to be careful with what you end your sentences."
or
"You'll have to be careful with which word types you end your
sentences."

Golly that was tricky. In fact the 2nd is probably slightly clearer
than the original...
And what, pray, are any rules of grammar but "because thats how it
is"? Be sensible.


Linguistics is a science.


ROFL.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

<snip>

Pray tell me ppl, what all this hogwash got to do with Standard C ??

I think everyone parsed what was said by the original author, so why
bother?
Regards,
Frodo Baggins

Nov 15 '05 #33

P: n/a
"Frodo Baggins" <fr*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Mark McIntyre wrote:
On Sun, 09 Oct 2005 02:09:41 +0200, in comp.lang.c , Skarmander
<in*****@dontmailme.com> wrote:
and
when I'm around you I'll have to be careful about what I end my
sentences with.

Try to reformulate that last sentence to comply with the vaunted rule,by the way. It's instructive. :-)


I'll just try the last clause if its ok:

"You'll have to be careful with what you end your sentences."
or
"You'll have to be careful with which word types you end your
sentences."

Pray tell me ppl, what all this hogwash got to do with Standard C ??


That would be, "what has" or "what's". And real words have vowels.

The Standard was written in Standard English. I think I can safely say
that the inventors of BCPL and C were English speakers. English is the
language we are communicating in; whether you are a native speaker or
not. So some semblance of proper English (American English of course,
none of that Limey crap) is required and therefore quite on topic.

--
Mabden
Nov 15 '05 #34

P: n/a
In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:
....
The Standard was written in Standard English. I think I can safely say
that the inventors of BCPL and C were English speakers. English is the
language we are communicating in; whether you are a native speaker or
not. So some semblance of proper English (American English of course,
none of that Limey crap) is required and therefore quite on topic.


Sing it, sister!

Nov 15 '05 #35

P: n/a
In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:
So some semblance of proper English (American English of course,
none of that Limey crap)


You mean not English English?

-- Richard
Nov 15 '05 #36

P: n/a
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:
So some semblance of proper English (American English of course,
none of that Limey crap)


You mean not English English?


Just in case anyone takes this seriously, English English is perfectly
acceptable, and we usually don't worry much about minor spelling and
grammatical mistakes. We do object to silly abbreviations suitable
for a mobile phone keypad, like "u" for "you", and "ppl" for "people";
they make text much more difficult to read.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #37

P: n/a
vvk4 wrote:
I have an excel spreadsheet that I need to parse. I was thinking of saving
this as a CSV file. And then reading the file using C. The actual in EXCEL
looks like:
a,b a"b a","b a,",b

In CSV format looks like:
"a,b","a""b","a"",""b","a,"",b"

Does anybody have suggestions or have C program based code to parse CSV.


I'm sorry to see you've gotten such worthless responses to your request
before I've managed to come across it. You can find some source here:

http://www.pobox.com/~qed/bcsv.zip

It does the proper thing with respect to quotes, reading input lines
etc, and just feeds the output through a row, column indexed callback.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 15 '05 #38

P: n/a
Keith Thompson <ks***@mib.org> wrote in
news:ln************@nuthaus.mib.org:
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:
So some semblance of proper English (American English of course,
none of that Limey crap)


You mean not English English?


Just in case anyone takes this seriously, English English is perfectly
acceptable, and we usually don't worry much about minor spelling and
grammatical mistakes. We do object to silly abbreviations suitable
for a mobile phone keypad, like "u" for "you", and "ppl" for "people";
they make text much more difficult to read.


Such abbreviations also tend to make it harder for me. I am not a native
speaker, and I have a much easier time parsing content written in mostly
proper English (any variant will do usually) than the chat style. For
the longest time, I did not have the slightest clue what ppl meant, for
example. On more than one occasion, I thought it was a library.

My two cents.

Sinan
--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
Nov 15 '05 #39

P: n/a
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:
So some semblance of proper English (American English of course,
none of that Limey crap)


You mean not English English?


Just in case anyone takes this seriously, English English is perfectly
acceptable, and we usually don't worry much about minor spelling and
grammatical mistakes. We do object to silly abbreviations suitable
for a mobile phone keypad, like "u" for "you", and "ppl" for "people";
they make text much more difficult to read.


There you go pissing on my parade, again. I think I made the ppl point.
Why did you need to chime in with an insult to me? It seems like you
can't stand to have a little humour injected into the conversation,
without putting on the brake. What content did your post bring to the
conversation, except as some kind of Mabden putdown?! Lay off Keith,
plz.

(see how I used plz instead of please to tie in a little humour with the
topicality - neat, huh?! Since you have no sense of humour [or
proportion] I thought I would point it out. Again, a little Zen in the
criticism might help as well. You could have said something like, "There
are basically no words for the way, but we use words to illustrate the
way." Much better.)

--
Mabden
Nov 15 '05 #40

P: n/a
In article <mG*****************@newssvr21.news.prodigy.com> ,
Mabden <mabden@sbc_global.net> wrote:
(see how I used plz instead of please to tie in a little humour with the
topicality - neat, huh?! Since you have no sense of humour


When two people disagree about a joke, it's not always the one who
thinks it funny who has the better sense of humour.

-- Richard
Nov 15 '05 #41

P: n/a
Mabden wrote:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:

So some semblance of proper English (American English of course,
none of that Limey crap)

You mean not English English?
Just in case anyone takes this seriously, English English is perfectly ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^acceptable, and we usually don't worry much about minor spelling and
grammatical mistakes. We do object to silly abbreviations suitable
for a mobile phone keypad, like "u" for "you", and "ppl" for "people";
they make text much more difficult to read.


There you go pissing on my parade, again. I think I made the ppl point.


That was not in the post Keith was replying to, which is not to say you
did not make it. However, it was not visible when Keith replied.
Why did you need to chime in with an insult to me?
I see no insult to you.
It seems like you
can't stand to have a little humour injected into the conversation,
without putting on the brake.
From the first phrase in Keith's post it is obvious he did not believe
it was meant seriously.
What content did your post bring to the
conversation, except as some kind of Mabden putdown?! Lay off Keith,
He was clarifying for anyone who did not realise it that it was not
serious, and clarifying what the actual situation is.

Stop assuming people are out to get you. I doubt that you are important
enough for any of us to care one way or another about you.
plz.

(see how I used plz instead of please to tie in a little humour with the
topicality - neat, huh?! Since you have no sense of humour [or
proportion] I thought I would point it out. Again, a little Zen in the
criticism might help as well. You could have said something like, "There
are basically no words for the way, but we use words to illustrate the
way." Much better.)


I've yet to see any instance, including your comment above, where Zen
has clarified anything. Stating things clearly as Keith did does clarify
things.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #42

P: n/a
"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:dj***********@pc-news.cogsci.ed.ac.uk...
In article <mG*****************@newssvr21.news.prodigy.com> ,
Mabden <mabden@sbc_global.net> wrote:
(see how I used plz instead of please to tie in a little humour with thetopicality - neat, huh?! Since you have no sense of humour


When two people disagree about a joke, it's not always the one who
thinks it funny who has the better sense of humour.


When two people add no content it is twice the waste of time for
everyone in the world who has to read your comments. Try to post
something pertaining to the subject at hand (albeit, and off-topic one)
instead of whatever value you think you just added.

What does this have to do with parsing CSV files? Or grammar which was
the OT post I replied to?

Why not just STFU? Ego? Hubris? Again, like Keith's post, I ask what
content do you add for all to read, for all time? Believe me, I am not
worthy of your insults, just carry on and either add content or shut the
fuck up. Telling me that my post is not funny, is not helping the world.

Here, I'll try to help Mr. Tobin and Mr. Thompson: "I admit I may say
something Off Topic sometimes!!! I may make a joke that falls flat!! I
may take a moment of your time that you will never recover!!! My bad!"

Are we done yet?

--
Mabden
Nov 15 '05 #43

P: n/a
"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
news:9r************@news.flash-gordon.me.uk...
Mabden wrote:
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:

In article <dq******************@newssvr14.news.prodigy.com >,
Mabden <mabden@sbc_global.net> wrote:

>So some semblance of proper English (American English of course,
>none of that Limey crap)

You mean not English English?

Just in case anyone takes this seriously, English English is perfectly
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
acceptable, and we usually don't worry much about minor spelling and
grammatical mistakes. We do object to silly abbreviations suitable
for a mobile phone keypad, like "u" for "you", and "ppl" for
"people";they make text much more difficult to read.
There you go pissing on my parade, again. I think I made the ppl

point.
That was not in the post Keith was replying to, which is not to say you did not make it. However, it was not visible when Keith replied.
I made the "Limey" remark, and (I may be wrong, but) I believe that is
the genesis of his email, and Richard got in between. If I am wrong then
I agree I am too sensitive. I have come to be a little paranoid about
Mr. T because he seems to follow my posts with his own on this
newsgroup - usually in a negative way. (see "Keith Thompson is trolling
me", for more info - I'm trying to let it go and not mention it anymore
as he has others who champion him, but you asked)
Why did you need to chime in with an insult to me?


I see no insult to you.


I agree I am too sensitive.
> It seems like you
can't stand to have a little humour injected into the conversation,
without putting on the brake.


From the first phrase in Keith's post it is obvious he did not

believe it was meant seriously.
But, did anyone? Did Keith need to reassure the world that a post made
by ME (of all people) was the mandate of the newsgroup, and needed to be
immediately denied?! Were all the "Limey's" leaving the newsgroup
because I said we don't want none of those extra U's in words?!

I believe in Keith's country "humour" is spelled so that it doesn't
involve "YOU" (for Keith T's benefit [the guy has NO sense of humour]:
the joke is that other countries spell humour with an "extra" u, so I'm
joking that taking the "u" out of humor, takes the humor out of Keith
T - i.e.:"you"! See "u" sounds like "you" if you say them both out
loud...) Boy, it's hard to explain puns, nevermind jokes.

A woodpecker walks into a bar and says, "Where's the bar tender?" (Now,
you explain to KT why that's a joke, and how funny it is!)
> What content did your post bring to the
conversation, except as some kind of Mabden putdown?! Lay off Keith,
He was clarifying for anyone who did not realise it that it was not
serious, and clarifying what the actual situation is.


You seriously wrote that? You mean you consider me the leader of all
that is c.l.c?!!
Stop assuming people are out to get you. I doubt that you are important enough for any of us to care one way or another about you.
Duh.
"There are basically no words for the way, but we use words to
illustrate the way."


I've yet to see any instance, including your comment above, where Zen
has clarified anything.


You read the words. You dismissed the words. You are unenlightened.
Again, Duh! Zen "clarifies" when one has attained enlightenment. I
cannot "Zen" you! Zap! Those words are thousands of years old and you
dismiss them without thought. Without thought.

Stating things clearly as Keith did does clarify things.


And reveal nothing. I already said we don't like pll who say, "ppl"
'round here. He echoed my words, in a derogatory way. Thank you for
nothing at all.

--
Mabden
Nov 15 '05 #44

P: n/a
On 2005-10-19, we******@gmail.com <we******@gmail.com> wrote:
vvk4 wrote:
I have an excel spreadsheet that I need to parse. I was
thinking of saving this as a CSV file. And then reading the
file using C. The actual in EXCEL looks like:
a,b a"b a","b a,",b

In CSV format looks like:
"a,b","a""b","a"",""b","a,"",b"

Does anybody have suggestions or have C program based code to
parse CSV.


I'm sorry to see you've gotten such worthless responses to your
request before I've managed to come across it.


It's hard to give good answers since csv is not standardized.
Using a simpler, non-modal data format would be much easier to
handle. I belive the OP should convert his Excel spreadsheet to
tab-delimited instead, saving himself the headache.

Having said that, Kernighan and Pike's _The Practice of
Programming_ contains an implementation of a csv file reader in
several languanges, including C.

--
Neil Cerutti
Nov 15 '05 #45

P: n/a
"Neil Cerutti" <le*******@email.com> wrote in message
news:sl*********************@FIAD06.norwich.edu...
On 2005-10-19, we******@gmail.com <we******@gmail.com> wrote:
vvk4 wrote:
I have an excel spreadsheet that I need to parse. I was
thinking of saving this as a CSV file. And then reading the
file using C. The actual in EXCEL looks like:
a,b a"b a","b a,",b

In CSV format looks like:
"a,b","a""b","a"",""b","a,"",b"

Does anybody have suggestions or have C program based code to
parse CSV.
I'm sorry to see you've gotten such worthless responses to your
request before I've managed to come across it.


....and I helped! (reference to 1960's commercial)

It's hard to give good answers since csv is not standardized.
Using a simpler, non-modal data format would be much easier to
handle. I belive the OP should convert his Excel spreadsheet to
tab-delimited instead, saving himself the headache.


Indeed.

But has anyone noticed that the CSV appears wrong. Shouldn't it be
something like:

"a","b a"b a"",""b a,"","b"

NOT

"a,b","a""b","a"",""b","a,"",b" (as posted)

I haven't opened Excel to test this, but the posted code doesn't seem to
scan right.

--
Mabden
Nov 15 '05 #46

P: n/a
Mabden wrote:
"Neil Cerutti" <le*******@email.com> wrote in message
news:sl*********************@FIAD06.norwich.edu...
On 2005-10-19, we******@gmail.com <we******@gmail.com> wrote:
vvk4 wrote:
> I have an excel spreadsheet that I need to parse. I was
> thinking of saving this as a CSV file. And then reading the
> file using C. The actual in EXCEL looks like:
> a,b a"b a","b a,",b
>
> In CSV format looks like:
> "a,b","a""b","a"",""b","a,"",b"
>
> Does anybody have suggestions or have C program based code to
> parse CSV.

I'm sorry to see you've gotten such worthless responses to your
request before I've managed to come across it.


...and I helped! (reference to 1960's commercial)

It's hard to give good answers since csv is not standardized.
Using a simpler, non-modal data format would be much easier to
handle. I belive the OP should convert his Excel spreadsheet to
tab-delimited instead, saving himself the headache.


Indeed.

But has anyone noticed that the CSV appears wrong. Shouldn't it be
something like:

"a","b a"b a"",""b a,"","b"

NOT

"a,b","a""b","a"",""b","a,"",b" (as posted)

I haven't opened Excel to test this, but the posted code doesn't seem to
scan right.


No, the original posting is correct. You need to put quotes around
anything that contains a CR/LF, non-trimmed leading or trailing
whitespace, a comma (,) or a double quote (") character. In addition
any " characters in the data are always doubled up in order to keep the
parsing simplistic. Furthermore the quotes must be around the entire
entry.

This allows CSVs to hold fully arbitrary binary data, including text
with their own control and escape characters with no problems.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 15 '05 #47

This discussion thread is closed

Replies have been disabled for this discussion.