When the input string is e.g. "4.5" I want sscanf to not parse it as a integer. But now it does.
My code looks like this:
if (sscanf(str, "%d", &val) == 0) { return NULL; }
This does not work of course since sscanf parses "4.5" as 4 and does not return NULL
Thanks for help
>Solution :
sscanf("4.5", "%d", &val) does not parse "4.5" as 4. It parses the "4" as 4 and leaves the ".5" unparsed. You instead could do:
int val;
char c;
if (sscanf(str, "%d%c", &val, &c) != 1) { return NULL; }