Use strtol() instead of atoi(). atoi() doesn't detect, or return, certain kind of errors. strtol() does, AND it has more functionality (bases, etc).
And it has its variants, as well, strtod(), strtoll(), strtoul()...