输入一串字符,然后统计一下元音字母(a.e.i.o.u),大佬们救救孩子吧,求求你了

发布时间:2019-07-29 16:24:58

#include <stdio.h>
int main (void)
{
int cnt[5];
int j,m;
char s[80];
printf("Please enter your string:\n");
j=0;
while ((s[j]=getchar())!='\n')
j++;
s[j]='\0';
while (s[j]!='\0'){
switch (s[j]){
case 1:
if (s[j]='a')
cnt[0]++;
break;
case 2:
if (s[j]='e')
cnt[1]++;
break;
case 3:
if (s[j]='i')
cnt[2]++;
break;
case 4:
if (s[j]='o')
cnt[3]++;
break;
case 5:
if (s[j]='u')
cnt[4]++;
break;
}
}
printf("The number of vowel:%d\n",cnt[0]+cnt[1]+cnt[2]+cnt[3]+cnt[4]);
return 0;
}

推荐回答

按你的基础改的,你参考下

#include <stdio.h>int main (void){    int cnt[5]={0}; //要初始化的    int j,m;    char s[80];    printf("Please enter your string:\n");    j=0;    while ((s[j]=getchar())!='\n')        j++;    s[j]='\0';    j=0; //这个j要重新赋为0的    while (s[j]!='\0')        {            switch (s[j]) //你的1,2,3,4哪里来的?                {                    case 'a':                        cnt[0]++;                        break;                    case 'e':                        cnt[1]++;                        break;                    case 'i':                        cnt[2]++;                        break;                    case 'o':                        cnt[3]++;                        break;                    case 'u':                        cnt[4]++;                        break;                }                j++; //每次加1        }    printf("The number of vowel:%d\n",cnt[0]+cnt[1]+cnt[2]+cnt[3]+cnt[4]);    return 0;}

以上问题属网友观点,不代表本站立场,仅供参考!