I am trying to parse a string that has some numbers seperated by a space. However, these numbers could be integers or floats. Is there a way in scanf to parse both integers and numbers as one collective float?
For example:
float arg1, arg2 = 0;
sscanf("LINE 10 10", "LINE %f %f", &arg1, &arg2);
// and
sscanf("LINE 10.0 10.0", "LINE %f %f", &arg1, &arg2);
It just works, integers are special cases of floating points.
Note, however, that large integers might not be able to be represented precisely by floats (eg.
1e9 + 1), but I don’t think you bother about that.