leetcode-String to Integer (atoi)
int myAtoi(char* str) { int y=0,s=0; while(*str!='\0'){ if(*str==' '||*str=='\t') { str++;continue; }else if(*str=='-'){ s=1;*str++;break; }else if(*str=='+'){ s=0;*str++;break; } break; } while(*str!='\0'&&*str<='9'&&*str>='0'){ //printf("%c,%d\n",*str,y); if(y<=(INT_MAX/10)){ y=y*10; }else{ if(s==1) return INT_MIN; return INT_MAX; } if((*str-'0')>(INT_MAX-y)){ if(s==1) return INT_MIN; return INT_MAX; }else{ y+=(*str-'0'); } *str++; } if(s==0) return y; return 0-y; }