469,950 Members | 1,895 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Reading Comma Delimited Files

I'm attempting to write an input routine that reads from a comma delimited
file. I need to read in one record at a time, assign each field to a field
array and then continue with my normal processing. I am having no luck at
all finding different routines written in C to read delimited files of any
kind. I have a few ideas of how I might go about this but I bet I'm
re-inventing the wheel and there already exists some efficient code out
there already? Im not an expert in C but know it well enough to get by most
of the time. Am I missing something obvious?

Thanks

John
Nov 13 '05 #1
1 6417
John B. Lorenz wrote:

I'm attempting to write an input routine that reads from a comma delimited
file. I need to read in one record at a time, assign each field to a field
array and then continue with my normal processing. I am having no luck at
all finding different routines written in C to read delimited files of any
kind. I have a few ideas of how I might go about this but I bet I'm
re-inventing the wheel and there already exists some efficient code out
there already? Im not an expert in C but know it well enough to get by most
of the time. Am I missing something obvious?

The real problem is absolutely non-trivial. The first is natural
language. What's the difference between a delimiter and a separator? Did
we mean 'comma delimited' or did we really mean 'comma separated'?
Probably 'separated'. Regard this text line:

010,"Joe","","Wright, Jr.",20030707,1.1,,"Y"

What would you make from that? We can see that 'fields' are separated by
commas. We see that 'character' fields are delimited with '"'. Note the
delimiter allows commas within character fields. But, in fact, the line
itself does not contain enough information for us to determine what to
do its fields. Before you can make any sense out of this, someone has to
tell about the FORMAT of the thing or you have to be a good guesser. :-)
--
Joe Wright mailto:jo********@earthlink.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ron McCafferty | last post: by
3 posts views Thread by Elmo Watson | last post: by
4 posts views Thread by Hilary Cotter | last post: by
3 posts views Thread by Leonard Wright | last post: by
1 post views Thread by ungvichian | last post: by
3 posts views Thread by P K | last post: by
2 posts views Thread by Wes Peters | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.