471,047 Members | 1,222 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,047 software developers and data experts.

Reading a comma separated file

I have a very simple question, but I am rather inexperienced in C so I can't figure it out.

I have a bunch of comma separated files, and each field is in quotation marks. Individual records are separated by carriage returns. I want to be able to to go a given record (a specific line in the file) and the read the data in a specific field in that record into an int or a char depending on whether the entry in that field is a number or text.

So, how can I do this?
Aug 5 '06 #1
1 5756
Banfa
9,065 Expert Mod 8TB
Open the file
Read the line you require into a string (this in itself is not entirely simple)
Use a pointer to scan along the line to the field you require
Check to see if the field is a number or a string
If it's a number convert the text to the binary number
If it's a string just copy it to your output buffer
Close the file again

Look up functions

fopen
fgets
fread
fgetc
fclose

strtoul

char array (string) handling.
Aug 5 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by John B. Lorenz | last post: by
2 posts views Thread by pesso | last post: by
29 posts views Thread by yourmycaffiene | last post: by
2 posts views Thread by rodchar | last post: by
2 posts views Thread by Wes Peters | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.