What is wrong with this C program to count the occurences of each vowel?

前端 未结 5 2080
無奈伤痛
無奈伤痛 2021-01-22 20:47

PROBLEM:

Write a C program that prompts the user to enter a string of characters terminated by ENTER key (i.e. ‘\\n’) and then count the total number of the occurrence o

5条回答
  •  -上瘾入骨i
    2021-01-22 21:32

    (just for fun, my answer)

    int main(void)
    {
        int counter[5] = {0};
        int *i, c;
    
        printf("Please enter a string terminated by ENTER key:\n");
        while(i = counter, (c = getchar()) != '\n')
        {
            switch(c)
            {
              default: continue;
              case 'U'+' ': case 'U': ++ i;
              case 'O'+' ': case 'O': ++ i;
              case 'I'+' ': case 'I': ++ i;
              case 'E'+' ': case 'E': ++ i;
              case 'A'+' ': case 'A': ++*i;
            }
        }
    
        for(c = 0; c < 5;
    
        printf("counter[%d] = %d\n", c, counter[c++]));
    
        return 0;
    }
    

提交回复
热议问题