根据您的真实需要,这个问题有几种可能的答案:
int example[5] = {1,2,3,4,5};
char output[5];
int i;
Run Code Online (Sandbox Code Playgroud)
直接复制给出ASCII控制字符1 - 5
for (i = 0 ; i < 5 ; ++i)
{
output[i] = example[i];
}
Run Code Online (Sandbox Code Playgroud)
字符'1' - '5'
for (i = 0 ; i < 5 ; ++i)
{
output[i] = example[i] + '0';
}
Run Code Online (Sandbox Code Playgroud)
表示1 - 5的字符串.
char stringBuffer[20]; // Needs to be more than big enough to hold all the digits of an int
char* outputStrings[5];
for (i = 0 ; i < 5 ; ++i)
{
snprintf(stringBuffer, 20, "%d", example[i]);
// check for overrun omitted
outputStrings[i] = strdup(stringBuffer);
}
Run Code Online (Sandbox Code Playgroud)