c++ - 在一个数字和英文混杂的句子里,统计英文单词数,我的代码错在哪?
大家讲道理
大家讲道理 2017-04-17 13:12:33
0
5
558
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(5)
大家讲道理

What the hell are these whiles? Shouldn’t they be ifs?

小葫芦

Young man, this code of yours has a lot of bugs. If there are two consecutive spaces, there will be an extra note. If there is no period, you will miss a word. Please add the code

include <stdio.h>

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);

}

大家讲道理

What the hell are you doing playing f1? Shouldn’t the output be num

迷茫

Why not use regular expressions? ?

巴扎黑

Good comments
Are you counting letters or words?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template