You're online now.

Hurray! you are online now.

C program to replace vowels with special characters

Today we will write a program in c in which we will replace all those vowels in string by a special symbol.

If we talk about the strategy of this program, then the strategy is very simple, we will take a sting from the user and a special symbol by which we will replace the vowels that given special symbol. Let's get started...

#include <stdio.h>
    #include <conio.h>
    int main() {
        char str[100], ch;
        printf("\nEnter the String : ");
        printf("\nEnter Any Symbol which to Replace : ");
        scanf("%c", &ch);
        for(int i = 0; str[i] != '\0'; 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] = ch;
        printf("After Replace : %s", str);
        return 0;
    Enter the String : lapmos
    Enter Any Symbol which to Replace : $
    After Replace : l$pm$s
  • We have used two libraries in this program which is first library is a standard input our library and second library is console input out library.
  • Every program has a man function from where all the program start executing.
  • We declare an array of char datatype and a variable.
  • Which is called ‘str’, that is what we will use for this string which will have our string store and the variable called ‘ch’, we store the special symbol.
  • Printed a message to the user and got the user to input the string using the gets() function.
  • Input the special symbol in a variable called ‘ch’.
  • Started a for loop whose initial condition i = 0. The condition given to check str[i] !+ ‘\n’ which means until the sting ends and ‘i’ will be increment by 1 until when the condition become false.
  • Inside the for loop body we will check the vowels in this string by the if condition statement.
  • Print the screen replaced at last an the program will terminated.
🖤 0
Buy me coffee ☕



No comments here...