程序填空题:统计字符串中最长的单词
c
#include <stdio.h>
int findLongest( char str[] );
int main()
{
char sArr[100] = { 0 };
int loc, i;
gets(sArr);
loc = ;
for (i = loc; sArr[i] != ' ' && sArr[i] != '\0'; i++)
putchar(sArr[i]);
return 0;
}
int findLongest( char str[] )
{
int i = 0, Loc = 0, len = 0, lLoc = 0;
while (str[i] != '\0')
{
while (str[i] == ' ')
i++;
lLoc = i;
while (str[i] != ' ' && str[i] != '\0')
;
if (i -lLoc > len)
{
;
Loc = lLoc;
}
}
;
}
###输入样例
in
This is a C Program
###输出样例
out
Program
答案:
第1空:findLongest(sArr)
第2空:i++
第3空:len = i - lLoc
第4空:return Loc