1 #include <ctype.h>
2 #include <stdlib.h>
3 
atoi(const char * s)4 int atoi(const char* s) {
5     int n = 0, neg = 0;
6     while (isspace(*s))
7         s++;
8     switch (*s) {
9     case '-':
10         neg = 1;
11     case '+':
12         s++;
13     }
14     /* Compute n as a negative number to avoid overflow on INT_MIN */
15     while (isdigit(*s))
16         n = 10 * n - (*s++ - '0');
17     return neg ? n : -n;
18 }
19