When using the function atoi
(or strtol
or similar functions for that matter), how can you tell if the integer conversion failed or if the C-string
From the man page for strtol():
If endptr is not NULL, strtol() stores the address of the first invalid character in *endptr. If there were no digits at all, however, strtol() stores the original value of nptr in *endptr. (Thus, if *nptr is not
'\0'
but **endptr is'\0'
on return, the entire string was valid.)