On Thu, 7 Oct 2004, Chris Wolcott wrote:
C is not my 'native' language, so I'm asking what the most efficient way to validate a string as containing a numeric value is. The ato?() and sscanf() functions just stop when they encounter a non-numeric, but do not tell you that they did.
I need to verify that a string contains a valid numeric value. (I.E. " +100" not "1 + 00" nor even "1+00 ", let alone "BOB ") (ato?() & sscanf() would return NULL or 1 in each case.)
It sounds like strtol() is what you are looking for. From the man page:
The remainder of the string is converted to a long int value in the obvious manner, stopping at the first charac- ter which is not a valid digit in the given base. (In bases above 10, the letter `A' in either upper or lower case represents 10, `B' represents 11, and so forth, with `Z' representing 35.)
It's not the software that's free; it's you. - billyskank on Groklaw