Progga
Progga

Reputation: 343

Reading floats from string as 2 integers

I'm trying to read floats from string splitting them up to 2 integers.

sscanf(line, "%d.%d", &dec, &frac));

This works with strings like this:

"0.25"

But if theres an optional sign before the number, it doesn't work anymore.

"-0.25"

How can i 'tell' sscanf, that there might be an optional sign before the number?

Upvotes: 1

Views: 35

Answers (1)

Thomas Baruchel
Thomas Baruchel

Reputation: 7517

As far as I can see %d is fine because it is for signed integer, but the issue here comes from the fact that -0 is 0... You will have to find a workaround since I don't think you can find a clean and easy way for that specific case.

Upvotes: 2

Related Questions