Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Write a function atoi(s) to convert the string s into an integer value.
Write a function atoi(s) to convert the string s into an integer value.
//Mark to be considered

int atoi(char * str)

{

int len = strlen(str);

int ans = 0;

If ('-'! =str[0])

{

for(int I = 0; I & ltlen++i)

ans+=str[i]*pow( 10,len-I- 1); ///double power (double x, double y); Calculate the y power of x

Return ans

}

other

{

for(int I = 1; I & ltlen++i)

ans+=str[i]*pow( 10,len-I- 1);

return-ans;

}

}