http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/
Return Value
On success, the function returns the converted integral number as an int value.
If no valid conversion could be performed, a zero value is returned.
If the correct value is out of the range of representable values, INT_MAX or INT_MIN is returned.
So how I differ between atoi("poop") and atoi("0") and atoi("0000000")
Yes I can loop and check for all zeroes in case I get 0 result, but isn’t there a better way?
Notice: I use ANSI C89
That’s one of the reasons
atoiis sometimes considered unsafe. Usestrtol/strtoulinstead. And if you have it usestrtonum.The function
atoiis more dangerous than you might think. ThePOSIXstandard says:The C99 standard says this also: