search

Home  >  Q&A  >  body text

c++ - 在一个数字和英文混杂的句子里,统计英文单词数,我的代码错在哪?

大家讲道理大家讲道理2803 days ago552

reply all(5)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 13:14:33

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

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:14:33

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

    }

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:14:33

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

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:14:33

    Why not use regular expressions? ?

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:14:33

    Good comments
    Are you counting letters or words?

    reply
    0
  • Cancelreply