我有值为255的整数,并希望将它们保存到char数组中.我正在尝试一些测试:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
char string[10];
int integers[10]; //all under 255.
int j;
for(j=0; j<10; j++)
{
integers[j]=j;
}
int i;
for(i=0; i<10; i++)
{
string[i]=(char)integers[i];
}
printf("%s \n", string);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行调试器到程序结束时,字符串包含以下ascii值:
"\ 000\001\002\003\004\005\006\A\B\t" 的
首先我不明白为什么在006之后\ a出现并且最后是\ t?
其次我想知道是否有更好的方法来做我想要的事情?谢谢