How to Delete Vowels From String in C

In this tutorial, we will see a new concept that is Delete Vowels From String in C.

Steps to delete vowels from string in c

C Program to Remove Vowels from String

In this first, we take the string which is a normal string which contains vowels present in it. After that, as we know five vowels which are A, E, I, O, U.

We check these vowels in a string as we found the vowels in string we remove that vowels from the string. At the end we have the string which contains no vowels present in the string.

For implementing this, We use the simple array to store the string and using array indexing concept we check single characters present in the string and we check whether it’s a vowel or consonant  if we found the vowel character we skip that and if we found consonant we copy to new variable we continue this process till string ends. at the end of this process, we got new string stored which contains no vowels present.

Now we will see program how to delete vowels from string in c.

C Program to Remove Vowels from String

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include <stdio.h>#include <string.h> int check_vowel(char); int main(){  char s[100], t[100];  int i, j = 0;   printf(“Enter a string to delete vowels\n”);  gets(s);   for(i = 0; s[i] != ‘\0’; i++) {    if(check_vowel(s[i]) == 0) {       //not a vowel      t[j] = s[i];      j++;    }  }   t[j] = ‘\0’;   strcpy(s, t);    //We are changing initial string   printf(“String after deleting vowels: %s\n”, s);   return 0;} int check_vowel(char c){  switch(c) {    case ‘a’:    case ‘A’:    case ‘e’:    case ‘E’:    case ‘i’:    case ‘I’:    case ‘o’:    case ‘O’:    case ‘u’:    case ‘U’:      return 1;    default:      return 0;  }}

Output :

C Program to Remove Vowels from String
C Program to Remove Vowels from String

Explanation :

1. Declare Function to check vowel

2.  write main function.

3. Declare variable.

4. Take string from use.

5. Read string one by one character. and pass character to function.

6. In function check character is vowel or not if vowel return 1 else 0

7. In main we check value returned from function

8. If Value is 0 ( that is character is not vowel) then store character to temporary variable else continue.

9. Repeat this till String end.

10. Print String