I am trying to find how many vowels and consonants in my string in C

Posted by John Walter on Stack Overflow See other posts from Stack Overflow or by John Walter
Published on 2012-03-25T23:18:17Z Indexed on 2012/03/25 23:30 UTC
Read the original article Hit count: 266

Filed under:
|
|
 #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;
   }
 }

And the question is, what is wrong with my code? why counter is not working? Because I tried a lot of ways, and nothing works, maybe someone can explain for me.

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays