Home » C programs » C string programs

C program to eliminate/remove all vowels from a string

Here, we will learn how to eliminate/remove all vowels from a string?, in this program we are reading a string of 100 (maximum) characters, and printing the string after eliminating vowels from the string.

Here, we designed two user defined functions:

1) char isVowel(char ch)
This function will take a single character as an argument and return 0 if character is vowel else it will return 1.

2) void eliminateVowels(char *buf)
This function will take character pointer (input string) as an argument and eliminate/remove all vowels in it.

Logic to implement:

  1. Run a parent loop from 0 to NULL.
  2. Chech the character, whether it is vowel or not, if the character is vowel shift all characters to the left.
  3. To shift all characters to the left, run another loop from "i" (Parent loop's loop counter) to NULL.

Program to eliminate/remove all vowels from an input string in C

#include <stdio.h>
#define MAX 100

//function prototypes

This function will return o if 'ch' is vowel
else it will return 1
char isVowel(char ch);

This function will eliminate/remove all vowels
from a string 'buf'
void eliminateVowels(char *buf);

/*main function definition*/
int main()
	char str[MAX]={0};
	//read string
	printf("Enter string: ");
	scanf("%[^\n]s",str); //to read string with spaces
	//print Original string
	printf("Original string: %s\n",str);
	//eliminate vowles
	printf("After eliminating vowels string: %s\n",str);
	return 0;

//function definitions

char isVowel(char ch)
	if(	ch=='A' || ch=='a' ||
		ch=='E' || ch=='e' ||
		ch=='I' || ch=='i' ||
		ch=='O' || ch=='o' ||
		ch=='U' || ch=='u')
		return 0;
		return 1;

void eliminateVowels(char *buf)
	int i=0,j=0;
			//shift other character to the left
			for(j=i; buf[j]!='\0'; j++)


Enter string: Hi there, how are you?
Original string: Hi there, how are you? 
After eliminating vowels string: H thr, hw r y?

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.