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

4 comments:

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

    ReplyDelete
  2. Thanks alot

    www.tipstothepeople.blogspot.com for more

    ReplyDelete
  3. if A is in the text then the output will be wrong

    ReplyDelete
  4. 1st one doesnt work
    & 2nd one gives output wrong

    ReplyDelete