String-Replace

program to replace a string by another string

#include < stdio.h>
#include < conio.h>
#include < string.h>
main()
{
int i,j,mm,k=0,l3,l1,l2;
char a[200],b[50],c[50],ch;
clrscr();
printf("\nEnter the string : ");
gets(a);
printf("\nEnter the string to be deleted : ");
gets(b);
printf("\nReplace it with : ");
gets(c);
l1=strlen(a);
l2=strlen(b);
l3=strlen(c);
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 replace it(y/n) : ");
ch=getche();
if(ch=='y'||ch=='Y')
{
for(j=i;j < =l1-l2;j++)
a[j]=a[j+l2];
l1=strlen(a);
for(mm=0;mm < l3;mm++)
for(j=l1+l3-1;j>i;j--)
a[j]=a[j-1];
for(j=0;j < l3;j++)
a[i+j]=c[j];
l1=strlen(a);
printf("\n\n%s",a);
}
}
}
}
if(k==0)
printf("Not found");
getch();
}C-Programming Standards & Guidelines: Version USearch Amazon.com for cprogramming

0 comments: