Hello.
I am trying to implement atoi(). Below is my code. It compiles correctly, but output is not correct. can anyone correct what wrong i am doing in logic here.
Here is my code.
Thanks.Code:#include<iostream> #include<string> #include<cmath> using namespace std; int myAtoi(const char*); int main(){ char abc[] = {"234"}; int c = myAtoi(abc); cout<<c; system("PAUSE"); } int myAtoi(const char* str){ if(str == NULL){ cout<<"String is empty"; return 0; } int sum = 0, j, len; len = strlen(str); j = len-1; while(j>=0){ sum = sum + (((int)str[j]) * (pow(10.0,j))); j--; } return sum; }