编一个子过程Delestr(s1,s2),将字符串s1中出现s2子字符串删去,结果还

2025-02-23 15:27:20
推荐回答(1个)
回答1:

//将字符串s中的子字符串s1全部替换为子字符串s2#defineN50#defineN110#defineN210#include#include//ifs1isasub-stringofs,return1//or,return0;intisSub(char*s,char*s1){char*p,*q;for(p=s,q=s1;*q;p++,q++){if(*p==0)return0;elseif(*p!=*q)return0;}return1;}//replaces1inswiths2voidreplace(char*s,char*s1,char*s2){intcnt=0,k,j;chartemp[N],*p;for(p=s;*p;p++){if(*p!=*s1)temp[cnt++]=*p;elseif(!isSub(p,s1))//testwhethers1isasub-stringofchar*ptemp[cnt++]=*p;//ifs1isnotasub-stringofchar*pelse//ifs1doisasub-stringofchar*p{k=strlen(s2);for(j=0;j