关闭。这个问题需要更多 focused 。它目前不接受答案。
想改善这个问题吗?更新问题,使其仅通过 editing this post 关注一个问题。
6年前关闭。
Improve this question
我有一个整数数组:
int a[5]={5,21,456,1,3}
我需要将这些数字存储到
char
数组中,以便 char 数组具有如下内容:char *s="52145613";
c 中是否有用于此的库函数?
最佳答案
sprintf
做你需要的。
小例子
char str[128];
int i=0;
int index = 0;
for (i=0; i<5; i++)
index += sprintf(&str[index], "%d", a[i]);
snprintf
处理 str 长度char str[128];
int i=0;
int index = 0;
for (i=0; i<5; i++)
index += snprintf(&str[index], 128-index, "%d", a[i]);
关于arrays - 如何将 int 数组转换为字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30234363/