C program to count total number of vowel or consonant in a string using switch case and pointer.
C program to count total number of vowel or consonant in a string using switch case and pointer.
#include <stdio.h>
#include <string.h>
#define MAX 100
int main()
{
char text[MAX];
char * s = text;
int vowel, consonant;
printf("\n Enter any string: ");
gets(text);
vowel = 0;
consonant = 0;
while(*s)
{
if((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <='Z'))
{
switch(*s)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
vowel++;
break;
default:
consonant++;
}
}
s++;
}
printf("\n Number of vowel in the enter string = %d", vowel);
printf("\n Number of consonant in the enter string = %d", consonant);
return 0;
}
Output:
Enter any string: computer
Number of vowel in the enter string = 3
Number of consonant in the enter string = 5