I'm parsing a string (a char *
) and I'm using sscanf
to parse numbers from the string into double
variables, like this:
while (*s) {
if (sscanf(s, " %1[MmLl] %f %f %n ", command, &x, &y, &n) == 3) {
//Do some processing
s += n;
}
}
This works for most of the inputs except few cases. The problem is with the count variable n
. For some input, the variable n is never updated and it continues to hold the count of the previous iteration. This results in a wrong offset and mess up the parsing.
I don't see anything weird with the input that is failing.
Note: This issue happens only in windows as the same code produces correct output in linux.
Has anyone faced similar issues?