Remove Vowels from String
Here you will get a program code to remove vowels from string using pointers in c language.
Program to Removes the Vowels Characters a , e, i , o ,u from the input string.
First we will input a string from the user, then start a loop from start point to end and check if the char is a vowel, if yes remove char else move to next char, at last print the string without vowels as result.
Remove Vowels from String using Pointers in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | //Remove vowels from string using pointers in C #include <stdio.h> #include <string.h> int main() { char str[80], *ptr; int i, j; // Input string printf("Enter a string: "); gets(str); ptr = str; while(*ptr != '\0') { // Check characters as vowel if(*ptr=='a' || *ptr=='e' || *ptr=='i' || *ptr=='o' || *ptr=='u' || *ptr=='A' || *ptr=='E' || *ptr=='I' || *ptr=='O' || *ptr=='U') { for(i=j=0; str[i]!='\0'; i++) { // Skip the vowels 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[j] = str[i]; j++; } } ptr = str; str[j] = '\0'; } else { ptr++; } } printf("String after vowels removed : %s", str); return 0; } |
Output
Enter a string: coderevise
String after vowels removed : cdrvs
Check out our other C programming Examples