1.有10个字符串,每个字符串表示一段文字,将10个字符串连接成一篇文章,保存到一维数组中并输出。c语言
时间: 2023-11-27 18:50:42 浏览: 93
以下是连接10个字符串并保存到数组的C语言代码示例:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str1[] = "Lorem ipsum dolor sit amet, ";
char str2[] = "consectetur adipiscing elit. ";
char str3[] = "Nullam nec purus eget neque ";
char str4[] = "pulvinar dignissim. ";
char str5[] = "Pellentesque habitant morbi ";
char str6[] = "tristique senectus et netus ";
char str7[] = "et malesuada fames ac turpis ";
char str8[] = "egestas. ";
char str9[] = "Maecenas mollis nec diam ";
char str10[] = "a tristique. ";
char article[1000];
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", article);
return 0;
}
```
输出结果为:
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nec purus eget neque pulvinar dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas mollis nec diam a tristique.
```
阅读全文