高洛峰2017-04-17 13:14:33
小伙子你这段代码的bug很多啊,如果连续两个空格就会出现多记,如果没有句号,你就会漏记一个单词,上码
int main()
{
char s[80] = {0};
char *p;
int num = 0;
unsigned char flag = 0;
gets(s);
p = s;
while(*p++)
{
if(( *p >= 'a' && *p <= 'z')||( *p >= 'A' && *p <= 'Z') )
{
flag = 1;
}
else if (flag == 1)
{
flag = 0;
num++;
}
}
printf("there are %d words\n",num);
}