C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs



Home » C solved programs » C string programs

C program to eliminate all vowels from a string






In this C program, we are going to learn how to eliminate all vowels from a given string? Here, we have a string that may contain consonants, vowels etc we have to remove only vowels from it.
Submitted by IncludeHelp, on April 05, 2018

Given a string and we have to eliminate/ remove all vowels from the string using C program.

To eliminate/remove the vowels

  • We will traverse (reach) each elements by using a loop
  • And, check the each element, if any element found as vowel, we will remove that shifting all other elements to the left
  • Finally, we will print the string - that will be a string without the vowels

Example:

    Input:
    String is: "Hello World"
    
    Output:
    String after removing vowels: "Hll Wrld"

Program to eliminate all vowels from the string in C




/* C program to eliminate all the vowels
* from the entered string
*/
#include <stdio.h>
#include <string.h>

int main()
{
	char string[50]={0};
	int length=0,i=0,j=0,k=0;

	printf("\nEnter the string : ");
	gets(string);

	length = strlen(string);

	for(j=0;j<length;j++)
	{
		switch(string[j])
		{
			case 'a':
			case 'A':
			case 'e':
			case 'E':
			case 'i':
			case 'I':
			case 'o':
			case 'O':
			case 'u':
			case 'U':
				for(k=j;k<length;k++)
				{
					string[k] = string[k+1];
					//printf("\nstring : %s",string);
				}
				length--;
				break;
			default : continue;
		}
	}
	
	printf("Final string is : %s",string);
	return 0;
	
}

Output

Enter the string : Hello World
Final string is : Hll Wrld






You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.


Comments and Discussions