Use strtol() or a related function to convert a string token to an integer. The strtol(), strtoll(), strtoul(), and strtoull() functions convert the initial portion of a string token to long int, long long int, unsigned long int, and unsigned long long int representation, respectively. These functions provide more robust error handling than alternative solutions.

References

\[[Klein 02|AA. C References#Klein 02]]
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]] Sections 7.20.1.4, "The strtol, strtoll, strtoul, and strtoull functions," 7.20.1.2, "The atoi, atol, and atoll functions," and 7.19.6.7, "The sscanf function"