Remove All Vowels From A String | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Your version is much faster in execution. Thank you for sharing.

woolee
Автор

Why do we need to put "\0" at the end?

m.a
Автор

Thanks, Dr. Kevin for the video. What I could not understand is how the length of the string remains the same before and after the removal of vowels? if we do strlen(s) before and after the removal, the length stays the same.

StackMemoryx
Автор

Great video :
// An alternative method

void remove_vowels(char *string){
char *vowels = "aeuioAEUIO";
int i_novowels = 0;
for(int i = 0; string[i]; i++){
bool is_vowel = false;
for(int j = 0; vowels[j]; j++){
if(vowels[j] == string[i]){
is_vowel = true;
break;
}
}
if(!is_vowel){
string[i_novowels++] = string[i];
}
}
string[i_novowels] = '\0';
}

justcurious
Автор

I tried this code in compiler...as the result the program showing only vowel values like 'iiea' 😅

AmjuriDenish
Автор

i tried it but it Didn't work. Can u tell me where is the mistake here?yes I didn’t include Upperclass vowels.
#include<stdio.h>
#include<string.h>
int main()
{ char ch[100];
int j=0, i=0;
printf("Insert your Statements:");
gets(ch);

while(i<strlen(ch))
{

{
ch[j]=ch[i];
j++;
}
i++;
}
ch[j]='\0';
printf("%s", ch);


}

joe_mama
Автор

i was trying to do smh like this, but i only changed all the vowels to #
#include<stdio.h>
#include<string.h>
char *remove_vowels(char string[]);
int main(){
char string1[]="I love you so";
printf("%s\n", string1);
printf("%s - changed string1\n", remove_vowels(string1));
return 0;
}
char *remove_vowels(char string[]){
int slen=strlen(string);
for(int i=0;i<slen;i++){

switch(string[i]){
case 'o': string[i]='#';
break;
case 'i': string[i]='#';
break;
case 'u': string[i]='#';
break;
case 'e': string[i]='#';
break;
case 'a': string[i]='#';
break;
case 'y': string[i]='#';
break;
}

}
return string;
}

m.bagin
Автор

I was able to create this with the for loop
#include <stdio.h>
#include <string.h>

int main()
{
int newpos = 0;
char a[] = "aeiou shall be removed";

for(int i=0;i<strlen(a);i++)
{
if(!(a[i]=='a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u'))
{
a[newpos] = a[i];
newpos++;
}
}
a[newpos]='\0';
printf("%s", a);
}

sketchupguru
Автор

I have one code😃😊 with your logic thankyou

#include <stdio.h>
#include<string.h>

int main() {
char str[500];
int i ;
scanf("%[^\n]%*c", str);
int n=strlen(str);
int j=0;
for(int i=0;i<=n;i++){
if(!(str[i]=='a'
{
str[j]=str[i];
j++;
}

}
str[j]='\0';
printf("%s\n", str);
return 0;
}

ashishtiwari