高洛峰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);
}