C语言 如果将数字2 转换成字符串"2" ???????

如题所述

两种方式

一种是itoa

一种是sprintf

比如

int a=2;
char s[11], s1[11];
itoa(a, s, 10);// s为转换后结果
sprintf(s1, "%d", a);//s1是转换后结果

itoa更高效一些

sprintf更通用 更灵活。 

追问

还有其他的方法吗?
用写代码的方式该怎么写呢

追答

没什么其他方法了。 自己写代码 无非是自行实现这个函数。
获取各个位,转为字符型。

温馨提示:答案为网友推荐,仅供参考
相似回答