使用itoa函数。
原型:extern char *itoa(int i);
参考代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a=125;
char b[50];
printf("%s\n",itoa(a,b,10));//把10进制的125转成字符并输出。
return 0;
}
/*
扩展资料:
注意事项
itoa() 函数有3个参数:第一个参数是要转换的数字,第二个参数是要写入转换结果的目标字符串,第三个参数是转移数字时所用的基数(进制)。在上例中,转换基数为10,就意味着以10为转换进制。10:十进制;2:二进制。
itoa 并不是一个标准的C函数,它是Windows特有的,如果要写跨平台的程序,请用sprintf。
标准库中有sprintf,功能比这个更强,用法跟printf类似:
参考资料来源:百度百科-itoa函数
一,整数型数字装换成字符型数字
如果是0~9的个位数,直接+‘0’,就可以了。
如果是多位整数,最简单的方法是利用sprintf函数,例:
#include <stdio.h>两种方法:一种是使用使用atoi函数。第二种是使用格式化输出。
atoi函数:函数原型:int atoi(const char *nptr);
参数nptr字符串,如果第一个非空格字符存在,是数字或者正负号则开始做类型转换,之后检测到非数字(包括结束符 \0) 字符时停止转换,返回整型数。否则,返回零。
附上代码:#include "stdio.h"#include "stdlib.h"#include "conio.h"void main(){char str[1024] = {0};int Interger;printf("输入一个数字:\n");scanf("%s", str);sscanf(str, "%d", &Interger);printf("转换为整形:%d\n", Interger);getch();}本回答被网友采纳