char *strrpc(char *str,char *oldstr,char *newstr) { int i = 0; char bstr[strlen(str)];//转换缓冲区 memset(bstr,0,sizeof(bstr)); for(i = 0; i < strlen(str); i++) { if(!strncmp(str+i,oldstr,strlen(oldstr))) {//查找目标字符串 strcat(bstr,newstr); i += strlen(oldstr) - 1; }else { strncat(bstr,str + i,1);//保存一字节进缓冲区 } } strcpy(str,bstr); return str; }
dstName = strrpc(srcName, "/sdb/data/","/mnt/usb33/download/"); 将字符串srcName中的/sdb/data/替换成后者