之前版本其实只是针对【"】转换成字符串【"】,【'】转换成【'】,即对HTML表单的值中,为了正常显示【"】和【'】而做得一个前处理。
以下函数才是真正实现字符转换为字符字符串的。
char *charTostr(const char *str,const char a,const char *srcrepstr){static char p[2];
int len = strlen(srcrepstr),tmpLen=0;
char *tmp,*tmpRepStr,*repStr;
tmpRepStr=(char*)malloc(len);
repStr=(char*)malloc(len);
while(*str){
if(*str==a){
if(repStr!=NULL){
tmpLen=strlen(repStr);
repStr=(char *)realloc(repStr,tmpLen+len+1);
strcpy(repStr,tmpRepStr);
strcat(repStr,srcrepstr);
tmpRepStr=(char *)realloc(tmpRepStr,tmpLen+len+1);
strcpy(tmpRepStr,repStr);
}else{
strcpy(repStr,srcrepstr);
strcpy(tmpRepStr,repStr);
}
}else{
*p=*str;
if(repStr!=NULL){
tmpLen=strlen(repStr);
repStr=(char *)realloc(repStr,tmpLen+1);
strcpy(repStr,tmpRepStr);
strcat(repStr,p);
tmpRepStr=(char *)realloc(tmpRepStr,tmpLen+1);
strcpy(tmpRepStr,repStr);
}else{
strcpy(repStr,p);
strcpy(tmpRepStr,repStr);
}
*p='\0';
printf("repStr=%s\n",repStr);
}
++str;
}
free(tmpRepStr);
*p = '\0';
return repStr;
}