在C语言中,将int类型转换为字符串可以使用sprintf函数或者itoa函数。
示例代码:
#include <stdio.h>
int main() {
int num = 123;
char str[10];
sprintf(str, "%d", num);
printf("转换后的字符串为:%s\n", str);
return 0;
}
输出结果:
转换后的字符串为:123
示例代码:
#include <stdio.h>
#include <stdlib.h>
int main() {
int num = 123;
char str[10];
itoa(num, str, 10);
printf("转换后的字符串为:%s\n", str);
return 0;
}
输出结果:
转换后的字符串为:123
以上是在C语言中将int类型转换为字符串的两种常用方法。
领取专属 10元无门槛券
手把手带您无忧上云