Weird problem: sscanf

P

PX

Greetings,

Say I want to read a file line by line so I used fgets(). And I want
to parse strings from each line of the file, I used sscanf(). But
there's a strange problem that each time I run the program, sscanf()
cannot read in first line of file correctly. It always appends a
character at the end of last string that's been parsed. I am working
on HP-UX using cc. Anybody has any clue?

Thanks a bunch!
 
N

nrk

PX said:
Greetings,

Say I want to read a file line by line so I used fgets(). And I want
to parse strings from each line of the file, I used sscanf(). But
there's a strange problem that each time I run the program, sscanf()
cannot read in first line of file correctly. It always appends a
character at the end of last string that's been parsed. I am working
on HP-UX using cc. Anybody has any clue?

Thanks a bunch!

Post a small, reasonably complete, preferably compilable piece of code
showing the problem. Without that, it's a bit like reading your fortune
off tea leaves.

-nrk.
 
A

Anupam

Greetings,

Say I want to read a file line by line so I used fgets(). And I want
to parse strings from each line of the file, I used sscanf(). But
there's a strange problem that each time I run the program, sscanf()
cannot read in first line of file correctly. It always appends a
character at the end of last string that's been parsed. I am working
on HP-UX using cc. Anybody has any clue?

Thanks a bunch!

Please post the smallest compilable piece of code which exhibits the
problem. The problem could be that fgets() keeps the newline while
sscanf() doesnt. It would be quite difficult to comment without
getting something more solid to digest.
Regards,
Anupam
 
M

Mark McIntyre

Greetings,

Say I want to read a file line by line so I used fgets(). And I want
to parse strings from each line of the file, I used sscanf(). But
there's a strange problem that each time I run the program, sscanf()
cannot read in first line of file correctly. It always appends a
character at the end of last string that's been parsed. I am working
on HP-UX using cc. Anybody has any clue?

Post a small example of your code. We're not telepathic... by the way,
whats the "extra character" ? 0x0d or 0x0a by any chance?
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top