我试图找到C中我的字符串中有多少个元音和辅音

Joh*_*ter -2 c arrays string

 #include <stdio.h>
 #include <string.h>

 int main()
 {
   int i;
   int counter=0, counter2=0;
   char *s;
   char name[30];
   char vowel[6] = "AEIOU";
   char consonants[21] = "BCDFGHJKLMNPQRSTVWXYZ";

   printf ("input the string: ");
   scanf  ("%s", name);
   printf ("The string is %s\n", name);
   for (i=0; name[i]!='\0'; i++) {
     if (s = strchr(vowel, name[i])) {
       counter++;
     }
     else if (s =strchr(consonants, name[i])) {
       counter2++;
     }
     printf ("First counter is %d\n", counter);
     printf ("The second counter is %d\n", counter2);
     return 0;
   }
 }
Run Code Online (Sandbox Code Playgroud)

问题是,我的代码出了什么问题?为什么柜台不起作用?因为我尝试了很多方法,没有任何作用,也许有人可以为我解释.

Bil*_*nch 10

我已经为你的代码添加了缩进,通过这样做,很明显你的问题是你的return和print语句都在for循环中.它们应该在循环之外.