Sign in to follow this  

Problems with fscanf

This topic is 2487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all!

I want to parse a file which has the following format:
[code]
foam offset: 10.00, 20.00
foam size: 1250.00, 600.00

melting radius: 1.30

supporters: 10

70.00
200.00
300.00
400.00
500.00
600.00
700.00
800.00
900.00
1000.00
[/code]

The code I have so far:
[code]
fscanf(stream,"foam offset: %lf, %lf",&FoamOffset[0],&FoamOffset[1]);
fscanf(stream,"foam size: %lf, lf\n",&FoamSize[0],&FoamSize[1]);

fscanf(stream,"melting radius: %lf",&ToolRadius);

fscanf(stream,"supporters: %d",&SupporterCount);

for( i = 0; i < SupporterCount; i++ )
{
fscanf(stream,"%lf",&SupporterPositions[i]);
}
[/code]
But it only reads the first line (debugged: all the other fcanfs return 0). According to the reference, the function should "[i]read and ignore any whitespace characters (this includes blank spaces and the newline and tab characters) which are encountered before the next non-whitespace character[/i]". But it seems it doesn't. Before I start to hack I ask it here: what's the problem? (and I want to keep it flexible in the future (so it should not be whitespace-sensitive))

Thanks in advance!

Share this post


Link to post
Share on other sites
Solved it.
I read id line by line, then read parse the lines with sscanf. I can parse simply and the lines can be in arbitrary order, but they must be in a new line in order to get parsed. Otherwise stuff that is in the same line won't be parsed. It's my "own format", i can afford to be so very strict about it...

Share this post


Link to post
Share on other sites

This topic is 2487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this