Q:

C program to eliminate/remove all vowels from a string

belongs to collection: C String Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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
	eliminateVowels(str);
	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;
	else
		return 1;
}

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

Output

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to eliminate/remove first character of e... >>
<< C program to read a string and print the length of...