#include<ctype.h>
#include <stdio.h>
/* atoi function:change string to integer**/
/*if there is space in the head,skip it*/
/*if it is "+" or "-" in the head,read it*/
int atoi(char s[])
{
int i=0;//counter
bool negative;//to mark whether the string starts with '-'
int n=0;//the integer that returns
for(;isspace(s[i]);i++)
;
if(s[i]=='-')
{
negative=true;
i++;//I forgot this,madan!
}
else
negative=false;
for(;s[i]!='\0';i++)
{
n=n*10+(s[i]-'0'); //it is the key point
}
return negative? -1*n: n;
}
int main()
{
//test
printf("\n%d",atoi("-134"));
printf("\n%d",atoi("134"));
getchar();
}