#include <stdio.h>
#include <conio.h>
void main()
{
char a[100],b[10],t[20][20],c[10];
int i=0,n=0,w=1,k=0;
clrscr();
printf("\n Enter The String : ");
scanf("%[^\n]",a);
printf("\n Enter The Word Need To Replace : ");
scanf("%s",b);
printf("\nEnter The New Word : ");
scanf("%s",c);
while(a[i]!='\0')
{
t[k][n]=a[i];
if(a[i]==' ')
{
t[k][n]='\0';
//printf("\n %s",t);
n=-1;
k++;
}
i++;
n++;
}
printf("\n the replaced string is : \t");
for(i=0;i<k+1;i++)
{
if(strcmp(t[i],b)==0)
strcpy(t[i],c);
printf(" %s ",t[i]);
}
getch();
}
/*
******
OUTPUT
******
Enter The String : This is a sample program
Enter The Word Need To Replace : sample
Enter The New Word : demo
The replaced string is : This is a demo program
*/