正在加载图片...
③ Relplacestring实现 char * replacestring(char*s, char *oldstr char* newstr) char pl=s, p2, tmpfield MAX LENI int nlen=oilen while((p2=strstr(pl, oldstr ))!=NULL& ilen=p2-pI memcpy (tmpfield-+nlen,pl, ilen) memcpy(tmpfield-+nlen+ilen, newstr, strlen(newstr)); nlen+=ilen+strlen(newstr); pl=p2+strlen(oldstr) 1//while if(pl=s) i memcpy (tmpfield+nlen,pl, strlen(pl)) nlen+=strlen(p1) memmove(s, tmpfield nlen salen 3/if 3/ replacestring ypb@ustc.edu.cn 中国科学技术大学ypb@ustc.edu.cn 7 中国科学技术大学 char *replacestring(char *s,char *oldstr, char* newstr){ char *p1=s,*p2,tmpfield[MAX_LEN]; int nlen=0,ilen; while((p2=strstr(p1,oldstr))!=NULL){ ilen=p2-p1; memcpy(tmpfield+nlen,p1,ilen); memcpy(tmpfield+nlen+ilen,newstr,strlen(newstr)); nlen+=ilen+strlen(newstr); p1=p2+strlen(oldstr); } //while if(p1!=s) { memcpy(tmpfield+nlen,p1,strlen(p1)); nlen+=strlen(p1); memmove(s,tmpfield,nlen); s[nlen]=‘\0’; } //if } // replacestring Relplacestring实现
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有