每天进步一点点
long long int WeAtoll(const char* str_ptr)
{
int size = strlen(str_ptr);
while ((*str_ptr == ' ' || *str_ptr == '-' || *str_ptr == '+')) {
str_ptr++;
size--;
}
const char* str_ptr_cpy = str_ptr;
long long int digtal = 0;
long long int out_flow = 0;
while (*str_ptr != '\0') {
if (*str_ptr < '0' || *str_ptr > '9') {
break;
}
out_flow = digtal;
digtal = digtal * 10 + (*str_ptr - '0');
if (out_flow > digtal) { // 出现溢出才会出现这种情况
str_ptr_cpy--;
if (*str_ptr_cpy == '-') {
return LLONG_MIN;
}
return LLONG_MAX;
}
str_ptr++;
}
str_ptr_cpy--;
if (*str_ptr_cpy == '-') {
digtal = -digtal;
}
return digtal;
}