有10个字符串,每个字符串表示一段文字,将10个字符串连接成一篇文章,保存到一维数组中并输出。 c语言
时间: 2023-08-04 22:05:47 浏览: 422
以下是一个示例代码,将10个字符串连接成一篇文章并存储到一维数组中:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Lorem ipsum dolor sit amet, ";
char str2[] = "consectetur adipiscing elit, ";
char str3[] = "sed do eiusmod tempor incididunt ";
char str4[] = "ut labore et dolore magna aliqua. ";
char str5[] = "Ut enim ad minim veniam, ";
char str6[] = "quis nostrud exercitation ullamco ";
char str7[] = "laboris nisi ut aliquip ex ea commodo ";
char str8[] = "consequat. Duis aute irure dolor in ";
char str9[] = "reprehenderit in voluptate velit ";
char str10[] = "esse cillum dolore eu fugiat nulla pariatur.";
char article[500]; // 保存文章的数组,需要足够大
// 将每个字符串拼接到文章数组中
strcpy(article, str1);
strcat(article, str2);
strcat(article, str3);
strcat(article, str4);
strcat(article, str5);
strcat(article, str6);
strcat(article, str7);
strcat(article, str8);
strcat(article, str9);
strcat(article, str10);
printf("%s\n", article); // 输出文章
return 0;
}
```
输出结果为:
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
```
阅读全文