C Program To Remove Vowels From String
Here’s a Program Code To Remove Vowels From String in C Programming Language without using any Library Function. This Program Code accepts a String or an Array of Characters and Saves (Copies) all the Non – Vowel Characters into another String.
What are Vowels?
A Letter representing a Vowel Sound having these Letters: A, E, I, O, U.
It is possible to Compare these Vowels by using ASCII Values of the Letters (Vowels in this case) or by directly using Comparison Operator and Remove the Vowels from the String as done in the following Program Code (Method 1).
Here, Library Method strlen() is used to calculate the Length of the String accepted by the User. The Library Function for the same is defined in the string.h Header File.
Also Read: C Program To Solve Tower of Hanoi Problem
Method 1: Code To Remove Vowels From String in C Programming Language
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 | #include<stdio.h> #include<string.h> int main() { char str1[50], str2[50]; int length = 0, count, a = 0; printf("\nEnter A String:\t"); scanf("%s", str1); length = strlen(str1); for(count = 0; count <= length; count++) { if((str1[count] == 'a' || str1[count] == 'e' || str1[count] == 'i' || str1[count] == 'o' || str1[count] == 'u') ||(str1[count] == 'A' || str1[count] == 'E' || str1[count] == 'I' || str1[count] == 'O' || str1[count] == 'U' )) { str1[count] = ' '; } else { str2[a++] = str1[count]; } } str2[a] = '\0'; printf("\nString After Removing Vowels:\t%s\n\n", str2); return 0; } |
Method 2: C Program To Delete Vowels From String using ASCII Character Value
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 | #include<stdio.h> #include<string.h> int main() { char str1[50], str2[50]; int length = 0, count, a = 0; printf("\nEnter A String:\t"); scanf("%s", str1); length = strlen(str1); for(count = 0; count <= length; count++) { if((str1[count] == 97 || str1[count] == 101 || str1[count] == 105 || str1[count] == 111 || str1[count] == 117) ||(str1[count] == 65 || str1[count] == 69 || str1[count] == 73 || str1[count] == 79 || str1[count] == 85 )) { str1[count] = ' '; } else { str2[a++] = str1[count]; } } str2[a] = '\0'; printf("\nString After Removing Vowels:\t%s\n\n", str2); return 0; } |
Also Read: C Program To Print Map of India using Obfuscated Code
Output

If you have any Compilation Error or Doubts in this C Program To Remove Vowels From A String, let us know about it in the Comment Section below.
Thanks. The second method for finding characters by ASCII values is comparatively easy. Thanks for both these methods.
This version does the following:
1) In some not optimized compilers or with options, eliminate the necessity to calculate the address of arr1[count] many times;
2) Removes the necessity of continue changing the == and || to != and &&. It does no change the quantity of verifications but simplify the code a little bit;
I am confused between = operator and == operator. Please help me.
== : Comparison Operator
= : Assignment Operator
Assignment Operator is used to store some value in the LHS variable.
Comparison Operator just compares the two variables on LHS and RHS.
Is it possible to eliminate vowels from strings using Pointers?