Giuseppe Bilotta <giuseppe.bilo...@gmail.com> writes: > Not in the sense I mean above. If the string is a sequences of > whitespace characters, strtod would return 0 as value (no conversion), > and set endptr to the end of the string, because it would gobble the > whitespace. This would be indistinguishable from it successfully > parsing a string argument of, say, '0.0'.
No, strtod requires a non-empty sequence of digits. #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char *blanks = " "; char *endptr; double x; x = strtod(blanks, &endptr); printf("x: %f endptr: \"%s\"\n", x, endptr); } $ ./a.out x: 0.000000 endptr: " " strtod is actually not a terrible function (surprising for libc, I know) > Hm. Since we have to do it both for scale and gamma, I wonder if it's > overengineering if I try to refactor this parsing of "N or 1 positive > values with separator S" into its own function. Yes. I'd just use sscanf or strtod directly as you please. -- -keith
signature.asc
Description: PGP signature
_______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: https://lists.x.org/mailman/listinfo/xorg-devel