DELETE THE VOWELS FROM A STRING USING C PROGRAM

#include<stdio.h>
int main(){
    char str[20],s[20];
    int i,j=0;
    printf("Enter any string->");
    scanf("%s",str);
    printf("The string is->%s",str);
   for(i=0;i<=strlen(str);i++) {  

        if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
                str[i]=' ';
        else 
                s[j++]=str[i];
    } 
    s[j]='\0';
    printf("\nThe string without vowel is->%s",s);
    return 0;
}





Also for the vowel in upper case:



#include<stdio.h>
#include<string.h>
int main(){
    char str[20],s[20];
    int i,j=0;
    printf("Enter any string->");
    scanf("%s",str);
    printf("The string is->%s",str);
   for(i=0;i<=strlen(str);i++) {  
        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')
                str[i]=' ';
        else 
                s[j++]=str[i];
    } 
    s[j]='\0';
    printf("\nThe string without vowel is->%s",s);
    return 0;
}

6 comments:

Anonymous said...

Great and simple to understand program however the if statement needs to have the || i.e. or between the various vowel checks.

Anonymous said...

Thanks alot

www.tipstothepeople.blogspot.com for more

Anonymous said...

if A is in the text then the output will be wrong

Yasin Hasan said...

1st one doesnt work
& 2nd one gives output wrong

Hari Cruz said...

should not be = in condition in the for loop for(i=0;i<=strlen(s);i++)
since a string of length 4 say
home is stored as
0123.so no = needed.

nadiya said...

Nice blog was really feeling good to read it. Thanks for this information.
Spoken English Classes in Chennai
Best Spoken English Class in Chennai
German Classes in Chennai
pearson vue exam centers in chennai
Informatica MDM Training in Chennai
Hadoop Admin Training in Chennai
Spoken English Classes in Tnagar
Spoken English Classes in OMR