发布时间:2019-07-29 16:24:58
按你的基础改的,你参考下
#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;}