Monday, July 28, 2008

C Source code for Converting from string to integer - atoi implementation

int StrToInt( char str[]) {

bool bFlagNeative =false;
if( str[0] == '-') {

bFlagNeative =true;
}
int i=0;
int num =0;
while(str[i] != '\0') {

num *=10;
num+= (str[i++] - '0');
}
if(bFlagNeative)
num *= -1;
return num;

}

No comments:

Your Title