1.临时空间给了个1024,不需要可减少长度。

2.结果只用用strcpy了,没校验。

 bool Replace(char *str,const char *src, const char *des)
{
  /* old -> new */
  int srclen = strlen(src);
  int deslen = strlen(des);
  int siplen = ;
  int buflen = ;
  char *pos = str;
  char *ptr = NULL;   static char buf[];   memset(buf, 0x00, );
  if(strcmp(src,des) == )
    return true;
    if(strlen(str) < srclen){
    // The lenth of old word is more then string!
    return false;
  }   while((ptr = strstr(pos, src)) != NULL) {
    siplen = ptr - pos;
    memcpy(buf + buflen, pos, siplen);
    strcat(buf, des);     buflen += siplen + deslen;
    pos = pos + siplen + srclen;
  }   if (buflen != ) {
    strcpy(buf + buflen, pos);
    strcpy(str, buf);
  }   return true;
}
05-28 06:52