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;
}

5 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

Unknown said...

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

Unknown 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.