String -Delete

program to delete a substring from a string

#include < stdio.h>
#include < conio.h>
#include < string.h>
main()
{
int i,j,k=0,l1,l2;
char a[200],b[50],ch;
clrscr();
printf("\nEnter the string : ");
gets(a);
printf("\nEnter the string to be deleted : ");
gets(b);
l1=strlen(a);
l2=strlen(b);
for(i=0;a[i]!='\0';i++)
{
if(b[0]==a[i])
{
k=1;
for(j=0;b[j]!='\0';j++)
{
if(a[i+j]!=b[j])
{
k--;
break;
}
}
if(b[j]=='\0')
{
printf("\nWord found do u want to delete it(y/n) : ");
ch=getche();
if(ch=='y'||ch=='Y')
{
for(j=i;j < l1-l2;j++)
a[j]=a[j+l2];
printf("\n\n%s",a);
}
}
}
}
if(k==0)
printf("Not found");
getch();
}

0 comments: