I read that atoi is deprecated and that it is equivalent to:
(int)strtol(token_start, (char **)NULL, 10);
does that mean I should use the above instead of atoi(chr) or is it just saying they are equivalent?
I read that atoi is deprecated and that it is equivalent to:
(int)strtol(token_start, (char **)NULL, 10);
does that mean I should use the above instead of atoi(chr) or is it just saying they are equivalent?
it means that at one point in time atoi will not be available anymore. So start changing your code now
from http://www.codecogs.com/reference/c/stdlib.h/atoi.php
Implementation Notes
* The atoi function is not thread-safe and also not async-cancel safe.
* The atoi function has been deprecated by strtol and should not be used in new code.
The description of atoi()
has one very important point in relation to the similarities/differences to strtol()
> ... The behaviour is the same as
> strtol(nptr, (char **)NULL, 10);
> except that atoi() does not detect errors.
Try this for fun:
const char *buf = "forty two";
int t1 = atoi(buf); /* detect errors? */
int t2 = strtol(buf, NULL, 10); /* detect errors? */