#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
int atoi(char *str)
{
int temp[64];
int i = 0;
int sum = 0;
bool isNeg = false;
if( *str == '-')
{
isNeg = true;
str++;
}
while(*str != '\0')
{
temp[i++] = *str - '0';
sum = sum*10 + *str - '0';
str++;
}
if(isNeg)
sum*=-1;
return sum;
}
int main()
{
char *str1 = "123";
char *str2 = "-984";
cout<<atoi(str1)<<endl;
cout<<atoi(str2)<<endl;
return 0;
}
#include <math.h>
#include <iostream>
using namespace std;
int atoi(char *str)
{
int temp[64];
int i = 0;
int sum = 0;
bool isNeg = false;
if( *str == '-')
{
isNeg = true;
str++;
}
while(*str != '\0')
{
temp[i++] = *str - '0';
sum = sum*10 + *str - '0';
str++;
}
if(isNeg)
sum*=-1;
return sum;
}
int main()
{
char *str1 = "123";
char *str2 = "-984";
cout<<atoi(str1)<<endl;
cout<<atoi(str2)<<endl;
return 0;
}