 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Someone Guest
|
Posted: Mon Sep 18, 2006 9:10 am Post subject: Import csv file problem |
|
|
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 |
|
| Back to top |
|
 |
Someone Guest
|
Posted: Mon Sep 18, 2006 9:10 am Post subject: Re: Import csv file problem |
|
|
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" <nospam (AT) gmail (DOT) com> wrote in message
news:eeliks$dv1$1$8300dec7 (AT) news (DOT) demon.co.uk...
| Quote: | 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
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|