C语言字符串拼接:添加空格分隔
下面是一个示例代码:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100] = 'Hello';
char str2[100] = 'world!';
char result[200];
// 拼接字符串并加上空格
sprintf(result, '%s %s', str1, str2);
printf('%s
', result);
return 0;
}
输出结果为:
Hello world!
该示例代码使用了 sprintf 函数来拼接字符串,并使用 %s 格式化字符串来表示要拼接的字符串。两个字符串之间通过空格来分隔。最后将拼接好的字符串存储到 result 数组中。
原文地址: https://www.cveoy.top/t/topic/lZPA 著作权归作者所有。请勿转载和采集!