int myatoi(const char* str);int main() {
char* str1 = \"-12\"; int a;
a = myatoi(str1); printf(\"%d\", a); return 0;}
int myatoi(const char* str) {
int value = 0; //存放值 int flat = 1; //判断正负 while(*str == ' ') { //跳过空字符 str++; }
if (*str == '-') { flat = 0; str++; }
else if (*str == '+') { flat = 1; str++; }
else if (*str<'0' || *str>'9') { //第⼀个字符为其他,直接跳出 return 0; }
while(*str >= '0' && *str <= '9' && *str != '\\0') { value = value * 10 + *str - '0'; str++; }
if (flat == 0) { value = -value; }
return value;}