C语言中如何将数字0转换成字符串呢?
谢谢各位大神了!
int 类型0~9的整数转换戚李此 char型 ,加上'0'即可,例如A=0时:扰迹
int A = 0;
char B = A + '0';
printf("%c\n", B);
输出结果高迅为字符0
//输入任意一个数字,转备棚激换为字仿袜符串输出
#include <stdio.h>
void main()
{
int n = 0;
char str[10]={0};
printf("input a number:");
scanf("%d"和灶, &n);
sprintf(str, "%d", n);
printf("the string is:[%s]\n", str);
}
你好!!
不知这是不是你想要的橡激代码:
#include<stdio.h>
void main()
{
char s[]="梁源袜0";
printf("%s\裂脊n",s);
}
结果:
0
Press any key to continue
数字0对应的ASCII是0x30,用一堆0x30就可以表示一个全是零的字符串了