用c语言编写程序输入若干个字符串求没个字符串的长度并打印最长的一个字符串的内容。以stop作为出入的最后一个字符串
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int len, maxLen = 0;
char maxStr[100];
printf("请输入若干个字符串,以\"stop\"为结束:\n");
while (1) {
scanf("%s", str);
if (strcmp(str, "stop") == 0) {
break;
}
len = strlen(str);
if (len > maxLen) {
maxLen = len;
strcpy(maxStr, str);
}
}
printf("最长的字符串为:%s\n", maxStr);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/bkyw 著作权归作者所有。请勿转载和采集!