本题要求从键盘上输入多个字符串(约定每个串不超过20个字符且没有空格,最多10个字符串),用""作为输入结束的标记(""不作为有效的字符串)。再从所输入的若干字符串中,找出一个最大的串,并输出该串。 如果没有合法字符串,则输出“NO WORD”。 请完成主函数剩余部分以及自定义函数的编写。
Count = Input(pStr, str);
if (Count == 0) puts("NO WORD");
else {
Find_max(pStr, Count, &max);
printf("max = %s", pStr[max]);
}
return 0;
}
int Input(char*pstr[], char (*s)[21]){
char t[22];
scanf("%s", t);
int i = 0;
while(strcmp(t, "*****") && i < 10) {
strcpy(*(s+i), t);
*(pstr+i) = *(s+i);
i++;
scanf("%s", t);
}
return i;
}
void Find_max(char*pstr[], int count, int*Max){
*Max = 0;
for (int i = 1; i < count; i++) {
if (strcmp(*(pstr+i), *(pstr+*Max)) > 0)
*Max = i;
}
}