以下是一个用 C 语言编写的程序,可以实现从键盘输入三个都不超过30个字符的字符串,输出其中最大的字符串,并将三个字符串连接在一起送入新地址并输出:
时间: 2023-11-28 22:47:54 浏览: 29
```c
#include <stdio.h>
#include <string.h>
#define MAX_LEN 30
int main() {
char str1[MAX_LEN+1], str2[MAX_LEN+1], str3[MAX_LEN+1];
char max_str[MAX_LEN+1], concat_str[3*MAX_LEN+1];
printf("Please enter three strings (no more than %d characters each):\n", MAX_LEN);
scanf("%s %s %s", str1, str2, str3);
// Find the maximum string
if (strcmp(str1, str2) > 0) {
strcpy(max_str, str1);
} else {
strcpy(max_str, str2);
}
if (strcmp(max_str, str3) < 0) {
strcpy(max_str, str3);
}
printf("The maximum string is: %s\n", max_str);
// Concatenate the three strings
strcpy(concat_str, str1);
strcat(concat_str, str2);
strcat(concat_str, str3);
printf("The concatenated strings are: %s\n", concat_str);
return 0;
}
```
注意:本程序未进行输入的合法性检查,如果输入的字符串超过了预设的长度,可能会导致错误。