有十个字符串,每个字符串表示一段文字。将十个字符串连成一片文章,保存到一维数组中并输出C语言
时间: 2023-08-18 17:07:49 浏览: 121
数组与字符串
下面是将十个字符串连成一篇文章的代码示例:
```c
#include <stdio.h>
int main() {
char str1[] = "Lorem ipsum dolor sit amet, ";
char str2[] = "consectetur adipiscing elit. ";
char str3[] = "Sed eget semper lorem. ";
char str4[] = "Proin interdum, nibh sed efficitur ";
char str5[] = "sodales, leo libero imperdiet urna, ";
char str6[] = "eget auctor sapien massa at turpis. ";
char str7[] = "Nam aliquam varius risus, ";
char str8[] = "a dictum dolor aliquet vel. ";
char str9[] = "Praesent quis justo sit amet dolor ";
char str10[] = "euismod lacinia. Sed nec orci nunc.";
char article[1000];
sprintf(article, "%s%s%s%s%s%s%s%s%s%s", str1, str2, str3, str4, str5, str6, str7, str8, str9, str10);
printf("%s\n", article);
return 0;
}
```
输出结果为:
```
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget semper lorem. Proin interdum, nibh sed efficitur sodales, leo libero imperdiet urna, eget auctor sapien massa at turpis. Nam aliquam varius risus, a dictum dolor aliquet vel. Praesent quis justo sit amet dolor euismod lacinia. Sed nec orci nunc.
```
阅读全文