The strtol(), strtoll(), strtoul(), and strtoull() functions convert the initial portion of a string pointed to long int, long long int, unsigned long int, and unsigned long long int representation, respectively.
The atoi(), atol(), and atoll() functions convert the initial portion of astring pointed to int, long int, and long long int representation, respectively. Except for the behavior on error, they are equivalent to
atoi: (int)strtol(nptr, (char **)NULL, 10) atol: strtol(nptr, (char **)NULL, 10) atoll: strtoll(nptr, (char **)NULL, 10)
However, it is better to use strtol() and related functions because atoi(), atol(), and atoll():
need not affect the value of the integer expression errno on an error and because if the value of the result cannot be represented, the behavior is undefined.
Non-Compliant Example
Compliant Solution
References
[] Section 7.20.1.4 The strtol, strtoll, strtoul, and strtoull functions