SUMMER TRAINING Free Tutorials  Go To Your University  Placement Preparation 
Project Based Best Summer Training Courses in Jaipur
Join our Telegram Channel To take free Online Courses
0 like 0 dislike
87 views
in GTU B.E. (CSE-I-Sem) Programming For Problem Solving Lab by Goeduhub's Expert (7.1k points)

Write a program to delete a character in given string using C programming

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

Delete from String

In this program we are going to search through a string for a character and delete it from the string.

To learn basics of string in C programming Click Here.

Example :

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[100],ch;
char chr;
int i,j;
clrscr();

//Taking input string from user
printf("\nEnter a string:");
gets(str);

//Taking character from user to delete
printf("\nEnter a Character to delete from string:");
scanf("%c",&ch);

//Accessing each element of string to perform delete operation
for(i=0;i<strlen(str);i++)
{
if(ch==str[i])
{

//After deleting user provided element moving each element one step forward to fill //it's place
for(j=i;j<strlen(str);j++)
str[j]=str[j+1];
}
}
printf("\nString after deleting character:\n");
puts(str);

getch();
}

Output :

Output of above program showing deletion of a character from string


For More GTU C Programming Lab Experiments Click Here

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...