#include<iostream>
using namespace std;
int my_aoti(const char*str)
{
int flag = 1;
int num = 0;
if (str == NULL)
{
cout << "ERROR" << endl;
return 0 ;
}
if (*str == '-' || *str == '+')
{
if (*str == '-')
{
flag = -1;
++str;
}
else
{
flag = 1;
++str;
}
}
while (*str != '\0')
{
if (*str >= '0'&&*str <= '9')
{
num = num * 10 + *str - '0';
++str;
}
else
{
break;
}
}
return num * flag;
}
int main()
{
const char*ch1 = "33460";
const char*ch2 = "-12345";
const char*ch3 = "123.12";
const char*ch4 = "+33460a";
cout << my_aoti(ch1) << endl;
cout << my_aoti(ch2) << endl;
cout << my_aoti(ch3) << endl;
cout << my_aoti(ch4) << endl;
}
|