Why is there no strtoi in stdlib.h?

Eli picture Eli · May 31, 2011 · Viewed 57.6k times · Source

I have grown accustomed to strtod and variants. I am wondering why there is no strtoi shipped with stdlib.h. Why is it that the integer is left out of this party?

Specifically I am asking why there is not a version of atoi with the safety features of strtod.

Answer

Wiz picture Wiz · May 31, 2011

strtol() converts a string to an integer, a long integer but an integer nevertheless. There is atoi() but it should be avoided in most cases due to the fact that it lacks a mechanism for error reporting from invalid input.