File manipulation problem

G

Gandu

Could a C guru please help me? Suppose I have an ASCII text file. Now, I want
to read in data from this file, line by line, and parse each line. What
would be a proper way to determine what the delimiter(csv, tsv) is, and
what is the character at the end of each line, i.e., the line-termination
character. Any help in this regard would be greatly appreciated.
 
P

Paul D. Boyle

: Could a C guru please help me? Suppose I have an ASCII text file. Now,
: I want to read in data from this file, line by line, and parse each
: line. What would be a proper way to determine what the delimiter(csv,
: tsv) is, and what is the character at the end of each line, i.e., the
: line-termination character. Any help in this regard would be greatly
: appreciated.

I'm not a C guru, but the way this is done as commonly recommended on
comp.lang.c is to use fgets() and sscanf(). fgets() reads the line
in and sscanf() parses the line. To see if the line is CSV or TSV,
you can use strchr(), and choose the appropriate format accordingly.

Check out comp.lang.c's FAQ for examples of fgets() and sscanf()
working together.

Paul
 
A

Al Bowers

Gandu said:
Could a C guru please help me? Suppose I have an ASCII text file. Now, I want
to read in data from this file, line by line, and parse each line. What
would be a proper way to determine what the delimiter(csv, tsv) is, and
what is the character at the end of each line, i.e., the line-termination
character. Any help in this regard would be greatly appreciated.

I am not a guru, but I have a few ideas.
If you are reading lines from the file, the newline character, '\n',
would be the delimiter. I would take a good study of the function
fgets. You will have to be careful, because it is possible for
data to be in the text file and not have the newline character.

Make an effort and post. Flaws will be identified and suggestions
will be made on improvements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top