写一个Atoi函数,实现字符串转换成整型数字
int MyAtoi(const char *p)
{
int result = 0;
int flag = 1;
if (*p == '-' || *p == '+' || (*p >= '0'&&*p <= '9'))
{
if (*p == '-')
{
flag = -1;
p++;
}
else if (*p == '+')
{
p++;
}
while (*p >= '0' && *p <= '9')
{
result = 10 * result + *p++ - '0';
}
}
return flag*result;
}