修改完成的#include<stdio.h>#include<conio.h>#include<string.h>int findreplace(char *s1, char *s2, char *s3){ int i,j,k=0,t=0; char temp[80]; if(*s1=='\0'||*s2=='\0') //判断要用== return 0; for(i=0; s1[i]!='\0'; i++) { for(j=i, k=0; s1[j]&&s1[j]==s2[k]; j++,k++) ;//j要从i开始 if(s2[k]=='\0') { strcpy(temp,&s1[j]); strcpy(s1+i,s3); i=i+strlen(s2)-2; //去掉两个多+的 strcpy(s1+i,temp); t=1; } } return t;}int main(){ char s1[80]="This is a sample program and sample data."; char s2[10]="sample",s3[10]="real",t; t=findreplace(s1,s2,s3); //参数为指针 if(t) puts(s1); else printf("not found"); getch(); return 0;}测试结果