#include<stdio.h>
#include<string.h>
int main()
{
int i=0;
char s[300],w1[10],w2[10],s2[400],*p,*p1;
printf("enter a string:\n");
scanf("%[^\n]s",s);
printf("enter the word to replace:\n");
scanf("%s",w1);
printf("enter the new word:\n");
scanf("%s",w2);
p=strstr(s,w1);
p1=s;
s2[0]='\0';
while(p!=NULL)
{
*p='\0';
strcat(s2,p1);
strcat(s2,w2);
p1=p+strlen(w1);
p++;
p=strstr(p,w1);
}
strcat(s2,p1);
printf("new string:\n%s",s2);
return 0;
}
No comments:
Post a Comment