现在的位置: 首页 > 综合 > 正文

整数转成字符串

2018年06月07日 ⁄ 综合 ⁄ 共 295字 ⁄ 字号 评论关闭
//整数转成字符串,可以采用加'0',再逆序的办法,整数加'0'就会隐性转成char类型的数
#include<stdio.h>
int main(void)
{
	int num=123456;
	int i=0,j=0;
	char temp[7],str[7];
	while(num)
	{
		temp[i]=num%10+'0';
		printf("%c\n",temp[i]);
		i++;
		num=num/10;
	}
	temp[i]=0;
	printf("temp=%s",temp);
	i=i-1;
	while(i>=0)
	{
		str[j++]=temp[i--];
	}
	str[j]='\0';
	printf("str=%s",str);
}

【上篇】
【下篇】

抱歉!评论已关闭.