方法一:数字+‘0’转换成字符
#include<stdio.h>
#include<string.h>
#include<malloc.h>
void main()
{
int inte_num;
int len,len_temp;;
char temp;
char *p;
char *q;
q=(char *)malloc(sizeof(char));
p=(char*)malloc(sizeof(char));
int i=0;
int j=0;
scanf("%d",&inte_num);
//len=strlen(inte_num);
//len_temp=len-1;
while(inte_num){
temp=inte_num%10;
p[i++]=temp+'0';
inte_num=inte_num/10;
}
//逆序
while(i>=0){
q[j++]=p[--i];
}
if(i=-1)
q[j]='\0';
// p[i]='\0';
printf("%s",q);
}
方法二:itoa函数,char *itoa(int value,char *string,int radix)
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
void main()
{
int inte_num;
char *p;
p=(char *)malloc(100*sizeof(char));
scanf("%d",&inte_num);
itoa(inte_num,p,10);
printf("%s",p);
free(p);
}