Mail Archives: djgpp/1999/07/29/16:02:49
On Tue, 26 Jan 1999, Dan Gold wrote:
> Could be offtopic, but It I want to detect if there is a letter in my
> character boxes but atoi returns zero if there is a letter. This is poorly
> designed because I can't use the number 0 when converting the integer
> string to an int variable.
`atoi' is one of the oldest functions in standard C libraries, so it
has to be compatible with its original design, since there are gobs of
programs out there which rely on this behavior.
If you need a conversion function that will also tell you when the
string is not a number, use `strtol'. It returns a pointer to the
first character in the string that it couldn't convert. If this
pointer points to something other than the terminating null character,
you know there's a non-digit in the input string.
- Raw text -