c语言编写,20个不同的整数或者字符串,合并成一个字符串
时间: 2023-07-16 20:14:57 浏览: 91
37_图像滤波综合示例,c语言中字符串相连源码,c语言
以下是一个合并20个不同字符串的示例代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "This";
char str2[] = "is";
char str3[] = "a";
char str4[] = "sample";
char str5[] = "string";
char str6[] = "for";
char str7[] = "merging";
char str8[] = "multiple";
char str9[] = "strings";
char str10[] = "into";
char str11[] = "a";
char str12[] = "single";
char str13[] = "string";
char str14[] = "in";
char str15[] = "C";
char str16[] = "language";
char str17[] = ".";
char str18[] = "Hope";
char str19[] = "this";
char str20[] = "helps!";
char result[1000];
strcpy(result, str1);
strcat(result, " ");
strcat(result, str2);
strcat(result, " ");
strcat(result, str3);
strcat(result, " ");
strcat(result, str4);
strcat(result, " ");
strcat(result, str5);
strcat(result, " ");
strcat(result, str6);
strcat(result, " ");
strcat(result, str7);
strcat(result, " ");
strcat(result, str8);
strcat(result, " ");
strcat(result, str9);
strcat(result, " ");
strcat(result, str10);
strcat(result, " ");
strcat(result, str11);
strcat(result, " ");
strcat(result, str12);
strcat(result, " ");
strcat(result, str13);
strcat(result, " ");
strcat(result, str14);
strcat(result, " ");
strcat(result, str15);
strcat(result, " ");
strcat(result, str16);
strcat(result, " ");
strcat(result, str17);
strcat(result, " ");
strcat(result, str18);
strcat(result, " ");
strcat(result, str19);
strcat(result, " ");
strcat(result, str20);
printf("%s", result);
return 0;
}
```
输出结果:
```
This is a sample string for merging multiple strings into a single string in C language. Hope this helps!
```
如果是整数,可以使用 sprintf() 函数将整数转换成字符串,然后再进行合并。
阅读全文