注意问题:
1.前导空白符;
2.包含‘+’或‘-’。
int my_atoi(const char *str)
{
if (str == NULL)
return 0;
int res = 0, sign = 1;
const char *p = str;
while(isspace(*p)) p++;
if(*p == '-'){
sign = -1;
p++;
}
else if (*p == '+'){
p++;
}
while(*p >= '0' && *p <= '9'){
res = res * 10 + *p - '0';
p++;
}
return res * sign;
}