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

Import csv file problem

P: n/a
Hello

Using the c file io functions if reading a csv file there is a problem if a
field contains an embedded carriage return. So I can check for apostrophe
pairs but processing does seem a bit of a struggle. Has anyone got a robust
algorithm or functions to use to reliably get a whole row of text from a csv
file even if some fields contain embedded carriage returns?

Angus
Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thought I better clarify:

Thought I better clarify:

Rules for a csv file are that each 'field' is separated by a comma (,) and
the end of each 'record' is terminated by a carriage return.

If a field contains a carriage return then you enclose the field in " and
" - quote marks. (Sorry apostrophe was wrong term to use).

So if I have this record:

1,1 The Avenue, New York, 345666,"hello in this field we have a carriage
return

more text here", 0233-444-7777,blue

If I use
char *fgets(char *s, size_t n, FILE *stream);

Then fgets gets to carriage return between two " "'s and I only half part of
the record.

I can obviously check if odd number of "'s in string and if so get to next
carriage return - but it does seem tricky getting it just right. I wondered
if anyone had come across this sort of thing before and how they got round
it?

Angus

"Someone" <no****@gmail.comwrote in message
news:ee*******************@news.demon.co.uk...
Hello

Using the c file io functions if reading a csv file there is a problem if
a
field contains an embedded carriage return. So I can check for apostrophe
pairs but processing does seem a bit of a struggle. Has anyone got a
robust
algorithm or functions to use to reliably get a whole row of text from a
csv
file even if some fields contain embedded carriage returns?

Angus


Sep 18 '06 #2

P: n/a
Someone wrote:
Thought I better clarify:
Why don't you first figure out which language you are working in. You
posted the same message to comp.lang.c.

Brian
Sep 18 '06 #3

P: n/a
On Mon, 18 Sep 2006 08:42:13 +0100 in comp.lang.c++, "Someone"
<no****@gmail.comwrote,
>Has anyone got a robust
algorithm or functions to use to reliably get a whole row of text from a csv
file even if some fields contain embedded carriage returns?
Hello, Angus. You still here? Are you still interested in this?

Sep 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.