字符串转换为数字(str2int)

// 将字符串转换为数字

int str2int(char *s)
{
    if (s==NULL) return 0;
    int temp=0;
    int vl=0;
    bool flag=false;
    while(*s!='\0')
    {
        if (*s=='-')
        {
            flag=1;
            s++;
        }
        temp = *s-'0';
        vl = vl*10+temp;
        s++;
    }
    return flag==true ? -vl:vl;
}

 

原文地址:https://www.cnblogs.com/yep3575/p/2888983.html