填空题:阅读下面程序,写出程序的运行结果。
阅读下面程序,写出程序的运行结果。
c
#include <stdio.h>
int main()
{
char str[] = "This is a Longer Road!";
int l = word_divide(str);
printf("%d\n", l);
return 0;
}
int word_divide( char str[] )
{
int count = 0;
int i = 0;
while (str[i] != '\0')
{
if (str[i] == ' ')
{
count++;
while (str[i] == ' ')
i++;
}
else
{
i++;
}
}
if (str[i-1] != ' ')
count++;
return count;
}
程序运行结果为:
答案:
第1空:5 ||
c
#include <stdio.h>
int main()
{
char str[] = "This is a Longer Road!";
int l = word_divide(str);
printf("%d\n", l);
return 0;
}
int word_divide( char str[] )
{
int count = 0;
int i = 0;
while (str[i] != '\0')
{
if (str[i] == ' ')
{
count++;
while (str[i] == ' ')
i++;
}
else
{
i++;
}
}
if (str[i-1] != ' ')
count++;
return count;
}
程序运行结果为:
答案:
第1空:5 ||