Saturday, January 21, 2012

Remove vowel in string

Q. write a C program for remove vowel in string and find the length of resulted string.

Ans.

/*c program for removing vowel in string and calculate length of new string*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
 int len=0,i,j=0;
 char str[40],new_str[30];
 printf("Enter any string : ");
 gets(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
   {
     len++;
     new_str[j++]=str[i];
   }
 }
 //Add null in new string
 new_str[j]='\0';
 printf("New vowel less string : %s",new_str);
 printf("\nLength of new string = %d",len);
 getch();
 return 0;
}

Output:-

Enter any string :John Cena Is Awesome
New vowel less string: Jhn Cn s wsm
Length of new string = 13

No comments:

Post a Comment