C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Strings in C

Remove Vowels from a String

C Program: Remove Vowels from a String

C

#include <stdio.h>

 

int main() {

    char str[200], result[200];

    int i, j = 0;

 

    // Input string

    printf("Enter a string: ");

    fgets(str, sizeof(str), stdin);

 

    // Remove vowels

    for (i = 0; str[i] != '\0'; i++) {

        // Check if character is NOT a vowel

        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')) {

            result[j++] = str[i];

        }

    }

 

    result[j] = '\0';  // Null terminate the result string

 

    printf("String after removing vowels: %s", result);

 

    return 0;

}

Output

 
OUTPUT :
Enter a string: It Developer
String after removing vowels: t Dvlpr

Explanation

  • The program reads a string using fgets().
  • It traverses each character of the string:
    • If the character is not a vowel, it is copied to the result
    • Vowels (both uppercase and lowercase) are skipped.
  • The result string is terminated with '\0'.