int str2int(const char *str)
{
int temp = 0;
const char *pstr = str;//ptr保存
if (*str=='-'||*str=='+')
{
str++;
}
while (*str!=0)
{
if ((*str < '0') || (*str > '9'))//如果当前字符不是数字,则退出循环
{
break;
}
temp = temp*10 + (*str - '0');//如果当前字符数数字则计算数值
str++;
}
if (*pstr =='-')//如果字符串是以"-"开头,则转换成其相反数
{
temp = -temp;
}
return temp;
}