#include
#include
main()
{
int lr,m,x,t,l,ll,ls,i,j,k,flag,count=0;
char line[200],str[20],rep[20];
printf(“Enter line of text\n”);
gets(line);
printf(“Enter the word to replace\n”);
scanf(“%s”,str);
printf(“Enter the word to replace with\n”);
scanf(“%s”,rep);
ll=strlen(line);
ls=strlen(str);
lr=strlen(rep);
for(i=0;i<ll;i++)
{
if(line[i]==str[0]&&((line[i-1]==’ ‘||i==0)&&(line[i+ls]==’ ‘||line[i+ls]==’\0′)))
{
for(flag=0,k=i,j=0;j{
if(line[k]==str[j])
{
flag++;
}
}
if(flag==ls)
{
if(lr>ls)
{
for(m=lr-ls;m>0;m–)
{
ll=strlen(line);
for(l=ll;l>i;l–)
{
line[l+1]=line[l];
}
}
}
else if(lr{
for(m=ls-lr;m>0;m–)
{
ll=strlen(line);
for(l=i;l<ll;l++)
{
line[l]=line[l+1];
}
}
}
else
{
}
for(x=0,t=i;x<lr;x++,t++)
{
line[t]=rep[x];
}
}
}
}
printf(“Text\n”);
puts(line);
}
Output :
Enter line of text
Snehal IS A GOOD GIRL
Enter the word to replace
GIRL
Enter the word to replace with
BOY
Text
Snehal IS A GOOD BOY
No comments:
Post a Comment