Description

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 string from the user and a special symbol by which we will replace the vowels that given special symbol.

Let's get Started the code...

#include <stdio.h>
#include <conio.h>
int main() {
    char str[100], ch;
    printf("\nEnter the String : ");
    gets(str);
    
    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

*/

If understand the program in detail...

  • We have used two libraries in this program which is first library is a standard input out library and second library is console input output library.
  • Every program has a main 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 stringusing the 'gets()' function.
  • Input the special symbol in a variable called 'ch'.
  • Started a for loop whose intial condition i = 0. The condition given to check str[i] != '\n' which means until the string ends and 'i' will be increament 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.
  • If vowels comes at any place, then we will replace it which given in the special symbol user.
  • Print the screen replaced at last and the program will terminated.

Please Comment...

Comments

Login is mandatory to comment Please login

Recommended Posts

File Read in C | File Handling | How to Read File

Write a program to read the file in c File Handling. How to read file is the main topic of file handling.

Insertion and deletion in doubly linked list in C program

Insertion and Deletion in Doubly linked list in C programming langauge Data Structure. How to Implement insertion and deletion all operation.

C program to check eligible for vote

Write a program to check that person is eligible for voting or not.

Voting program in C language using switch case

Write a program to check that person is eligible for voting or not using switch case.

C program to convert decimal to binary without Array

We can convert any decimal number into binary number by c program without using array.

A C program for checking whether a given line is a comment

Write a program in c to check whether a given line is comment or not.