In this tutorial you will learn about the C Program to Delete Vowels from String and its application with practical example.
C Program to Delete Vowels from String
In this tutorial, we will learn to create a C program that will Delete Vowels from String in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in c programming.
- Conditional statements in C programming.
- String functions of c programming.
Program to Delete Vowels from String
As we all know the String is a collection of character data types. In strings, only one variable is declared which can store multiple values. First, we will take the input string from the user. Then we will Delete Vowels from String using the while loop.
With the help of this program, we can Delete Vowels from String.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declare the variables for the program. 2. Take the input string from the user. 3. <strong>Delete Vowels from String</strong>. 4. Print the output. 5. End the program. |
Program to Delete Vowels from String:-
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 |
#include <stdio.h> #include <string.h> int check_vowel(char); int main() { //declaring the variables char s[100], t[100]; int i, d = 0; //taking the input string for the program printf("Enter a string to delete vowels\n"); gets(s); //checking and removing the vowels for (i = 0; s[i] != '\0'; i++) { if (check_vowel(s[i]) == 0) { // If not a vowel t[d] = s[i]; d++; } } t[d] = '\0'; strcpy(s, t); //optional strig changing printf("String after deleting vowels: %s\n", s); return 0; } int check_vowel(char t) { if (t == 'a' || t == 'A' || t == 'e' || t == 'E' || t == 'i' || t == 'I' || t =='o' || t=='O' || t == 'u' || t == 'U') return 1; return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- s[100] = it will hold the string value.
- t[100] = it will hold the string value.
- i = it will hold the integer value.
- d = it will hold the integer value.
Taking the input string from the user.