Learn How To Display and Print Vowels in String in C Programming. This C Program To Display Vowels of a String using ASCII Values, Switch Case and If Else Loop.
Must Read: C Program To Replace A String Character
The string function strlen() is defined in string.h header file. It is possible to compare the string characters with vowels using ASCII values as well as direct vowels.
Example
Coding Alpha
Vowels: o, i, a, A
Must Read: C Program To Remove String Vowels without Functions
C Program To Print Vowels in String using If Else Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<stdio.h> #include<string.h> int main() { int count, length; char str[30]; printf("\nEnter A String:\t"); scanf("%[^\n]s", str); length = strlen(str); for(count = 0; count < length; count++) { if(str[count] == 'a' || str[count] == 'e' || str[count] == 'i' || str[count] == 'o' || str[count] == 'u' || str[count] == 'A' || str[count] == 'E' || str[count] == 'I' || str[count] == 'O' || str[count] == 'U') { printf("Vowel at Position [%d]:\t%c\n", count, str[count]); } } return 0; } |
Must Read: C Program To Find Length of String without Functions
C Program To Display Vowels in String using ASCII Values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<stdio.h> #include<string.h> int main() { int count, length; char str[30]; printf("\nEnter A String:\t"); scanf("%[^\n]s", str); length = strlen(str); for(count = 0; count < length; count++) { if(str[count] == 97 || str[count] == 101 || str[count] == 105 || str[count] == 111 || str[count] == 117 || str[count] == 65 || str[count] == 69 || str[count] == 73 || str[count] == 79 || str[count] == 85) { printf("Vowel at Position [%d]:\t%c\n", count, str[count]); } } return 0; } |
Must Read: C Program To Reverse a String without Functions
C Program Find Vowels in a String using Switch Case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include<stdio.h> #include<string.h> int main() { int count, length; char ch, str[30]; printf("\nEnter A String:\t"); scanf("%[^\n]s", str); length = strlen(str); for(count = 0; count < length; count++) { ch = str[count]; switch(ch) { case 'a': printf("\nVowel: %c\n", str[count]); break; case 'e': printf("\nVowel: %c\n", str[count]); break; case 'i': printf("\nVowel: %c\n", str[count]); break; case 'o': printf("\nVowel: %c\n", str[count]); break; case 'u': printf("\nVowel: %c\n", str[count]); break; case 'A': printf("\nVowel: %c\n", str[count]); break; case 'E': printf("\nVowel: %c\n", str[count]); break; case 'I': printf("\nVowel: %c\n", str[count]); break; case 'O': printf("\nVowel: %c\n", str[count]); break; case 'U': printf("\nVowel: %c\n", str[count]); break; } } return 0; } |
Output

If you have any compilation errors or doubts in this C Program To Find String Vowels and Print them, let us know about it in the comment section below.