字符串数组->数字 atoi实现
作者:互联网
int Myatoi(const char *str)
{
assert(str != NULL);
if(str == NULL)
return 0;
int tmp = 0;
int flg = 1;//符号
while(*str == ' ')//开头空格
str++;
if(*str == '-')
{
flg = -1;
str++;
}
if(*str == '+')
{
str++;
}
while(isdigit(*str))//"123"->
{
tmp = tmp*10+ (*str-'0');
str++;
}
return flg*tmp;
}
标签:tmp,数组,++,int,atoi,str,字符串,NULL,flg 来源: https://blog.csdn.net/IWantPlayYasuo/article/details/102756596