我将如何做 c 中图像上显示的示例。即连接/append 字符串到一个字符串。字符串来自 char *array;。下面的功能会起作用吗?谢谢
ptr = strcat( s1, s2 );
然后我想打印连接的字符串
printf("the string is = %s ",joinedstring);
最佳答案
strcat
期望 s1
足够长以适应所有串联的结果。这意味着目标必须是 17 个字符长,因为字符串有 16 个字符,您还需要一个 char
作为空终止符。
此外,结果必须以空字符串开头,像这样:
char res[17] = {0};
strcat(res, "this");
strcat(res, ":");
strcat(res, "is");
... // and so on
关于在 C 中连接/追加字符串流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36534530/