//conver int to char
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
void IntToChar(int num);
int CharToInt(char *p);
void main()
{
int num=123456;
IntToChar(num);
char *string = new char[7];
string="123456";
int number=CharToInt(string);
printf("number is %d/n",number);
int mun=654321;
char str11[7];
itoa(mun,str11,10); 10表示10进制的。
for(int i=0;i<6;i++)
printf("str11[%d] is %c",i,str11[i]);
delete []string;
}
void IntToChar(int num)
{
char *str = new char[7];
char *temp = new char[7];
int i=0,j=0;
while(num)
{
temp[i]=num%10+'0';
i++;
num=num/10;
}
temp[i]=NULL;
printf("temp is :%s/n",temp);
i=i-1;
while(i>=0)
{
str[j]=temp[i];
i--;
j++;
}
str[j]=NULL;
printf("str is :%s/n",str);
delete []temp;
delete []str;
}
int CharToInt(char *r)
{
int num = 0;
int i=0;
while(r[i])
{
num=num*10+(r[i]-'0');
i++;
}
return num;
}