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 Anshuman Singh, on July 05, 2019

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, count = 0;

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

    length = strlen(string);
    count = length;
    for (j = 0; j < length;) {
        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 < count; k++) {
                string[k] = string[k + 1];
                //printf("\nstring : %s",string);
            }
            count--;
            break;
        default:
            j++;
        }
    }
    string[count] = '\0';
    printf("Final string is : %s", string);
    return 0;
}

Output

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.