Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

C program to remove vowels from a string.

How to remove vowels from a string.

In this article we will learn how to code a C program to remove vowels from a string. ‘A’, ‘E’, ‘I’, ‘O’, ‘U’ are five vowels out of 26 characters in English alphabet letters.C programming is case sensitive, and hence lowercase and uppercase characters are considered differently, so we will have to check for both the cases and then we can remove the vowels from a string

C program to remove vowels from a string

Algorithm:

  • Initialize the variables.
  • Accept the input.
  • Initialize for loop.
  • Check and delete the vowels.
  • Store the string without vowels using another for loop.
  • Terminate both for loop.
  • Print the string without vowels.

C programming code to remove vowels from a string.

#include <stdio.h>
#include <string.h>
int main()
{
//Initializing variable.
char str[100];
int i,j,len=0;

//Accepting input.
printf("Enter a string : ");
//gets(str);
scanf("%s",str);
len=strlen(str);

//Accepting input.
for(i=0; i<len; i++)
{
//Checking vowels.
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
{

//Deleting vowels.
for(j=i; j<len; j++)
{
//Storing string without vowels.
str[j]=str[j+1];
}
i--;
len--;
}
str[len+1]='\0';
}

printf("After deleting the vowels, the string will be : %s",str);

return 0;
}

Output

Enter a string : aaabbbeeeccc

After deleting the vowels, the string will be : bbbccc

One comment on “C program to remove vowels from a string.”


  • Argha

    #include
    #include
    int main()
    {
    //Initializing variable.
    char str[100];
    int i,j,len=0;

    //Accepting input.
    printf(“Enter a string : “);
    gets(str);
    len=strlen(str);

    //Accepting input.
    for(i=0; i<len; i++)
    {
    //Checking vowels.
    if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U')
    {

    //Deleting vowels.
    for(j=i; j<len; j++)
    {
    //Storing string without vowels.
    str[j]=str[j+1];
    }
    len–;
    i–;
    }
    }
    printf("After deleting the vowels, the string will be : %s",str);

    return 0;
    }

    If you dont write i– where i have written if there is consecutive vowels in a string it will skip the second vowel plz rectify it