#include
#include
#include
#define LEN 50
/*返回字符串数组strs中最长的元素位序*/
int findWord (char strs[][LEN], int len) {
int letterCntMax;
int i,letterCntMaxIndex;
letterCntMax = strlen(strs[0]);
letterCntMaxIndex = 0;
for (i=0; iif (strlen(strs[i])>letterCntMax) {
letterCntMax = strlen(strs[i]);
letterCntMaxIndex = i;
}
return letterCntMaxIndex;
}
int main (void) {
char strs[LEN][LEN] = {
"Let",
"freedom",
"ring",
"from",
"every",
"hill",
"and",
"molehill",
"of",
"Mississippi."
};
int len = 10;
int letterCntMaxIndex;
int i;
letterCntMaxIndex = findWord (strs, len);
printf ("英文句子:");
for (i=0; iprintf ("%s ", strs[i]);
putchar ('\n');
printf ("其中最长的单词:%s", strs[letterCntMaxIndex]);
putchar ('\n');
getch (); /*屏幕暂留*/
return 0;
}
运行结果