In this post we are going to make Extracting Vowels from A String In C
Algorithm
1. Declare Values
2. Taking String from User
3. Making Conditions
4. Using Switch
5. Printing No of Vowels
Code
#include <stdio.h>
int main()
{
int c = 0, count = 0;
char s[15];
printf("Enter a string\n");
gets(s);
while (s[c] != '\0')
{
switch(s[c])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
count++;
break;
}
c++;
}
printf("Number of vowels in the string: %d", count);
return 0;
}
Output
PS C:\Users\anmol> cd "c:\Users\anmol\OneDrive\Desktop\Collage\Sem-1\C Projects\" ; if ($?) { gcc tempCodeRunnerFile.c -o tempCodeRunnerFile } ; if ($?) { .\tempCodeRunnerFile }
Enter a string
Anmol
Number of vowels in the string: 2
PS C:\Users\anmol\OneDrive\Desktop\Collage\Sem-1\C Projects>