在函数输入中附加一个字符?

ary*_*ard 1 c

我需要send和integer到一个函数,然后将它追加到一个常量字符的末尾.

int main (void)
{
    append(1);
}

int append(int input)
{
    const char P = 'P';

    //This where I want to append 1 to P to create "P1"'
}
Run Code Online (Sandbox Code Playgroud)

Som*_*ude 5

无论你做什么,你需要将数字转换为字符串,否则你不能创建包含两个数字的字符串.

实际上,您可以在一个函数调用中组合串联和int到字符串的转换sprintf:

char output[16];
sprintf(output, "P%d", input);
Run Code Online (Sandbox Code Playgroud)