Category Archives: c program to remove the substring from the given string

C program to remove the substring from the given string

ALGORITHM:1. Start the program.
2. Declare the needed variables.
3. Get the string from user.
4. Get the substring from user to remove from the given string.
5. Remove the substring from the given string.
6. Finally print the remaining string.
7. Stop the program.
PROGRAM
#include stdio.h//put this <> in headerfile
#include conio.h
#include string.h
int i,j,k,l,remove_string_len=0;
void main()
{
char full_string[30],remove_string[30],result_string[30];
clrscr();
printf(“\nEnter the string\n”);
gets(full_string);
printf(“\nInput string -\”%s\”\n”,full_string);
printf(“\nEnter the string to remove “);
gets(remove_string);
remove_string_len=strlen(remove_string);
while(full_string[i]!=remove_string[j])
{
result_string[l++]=full_string[i];
i++;
}
for(k=0;k<=remove_string_len;k++)
{
if(full_string[i]==remove_string[k])
i++;
}
while(full_string[i]!='')
{
result_string[l++]=full_string[i];
i++;
}
result_string[l++]='';
printf("\nResult string after removal of substring \"%s\"",result_string);
getch();
}
OUTPUT:
Enter the string
ramkumar
Input string -“ramkumar”
Enter the string to remove ram
Result string after removal of substring “kumar”