代码如下:
#includeiostream
using namespace std;
int atio1(char *s)
{
int sign=1,num=0;
if(*s=='-')
sign=-1;
s++;
while((*s)!=' ')
{
num=num*10+(*s-'0');
s++;
}
return num*sign;
}
//itoa的实现
代码如下:
char *itoa(int num, char *str, int radix)
{
char* ptr = str;
int i;
int j;
while (num)
{
*ptr++ = string[num % radix];
num /= radix;
if (num radix)
{
*ptr++ = string[num];
*ptr = ' ';
break;
}
}
j = ptr - str - 1;
for (i = 0; i (ptr - str) / 2; i++)
{
int temp = str[i];
str[i] = str[j];
str[j--] = temp;
}
return str;
}
代码如下:
int main()
{
char *s="-123567890";
coutatio1(s);
system("pause");
}