void ConvertPicturePathFormat(std::string *strPath)
{
int nStringLength = strPath->length();
char *src = (char *) malloc (sizeof(char)*nStringLength + 1);
strcpy(src,strPath->c_str());
src[nStringLength] = '\0'; // we create a buffer that is twice bigger than the src buffer.
char *des = (char *)malloc(sizeof(char)*nStringLength*2);
memset(des,0,sizeof(des)); for (int i = 0,j = 0; i < nStringLength; i++,j++)
{
if (src[i] != '\\')
{
des[j] = src[i];//2. 从1 运行到这里后,des在调试窗口中的值为无效,为啥?
continue;
}
else
{
des[j] = '\\';
j++;
des[j] = '\\';//1. 运行到这里后,des后面没有被赋值的部分变成了"屯屯屯.."
}
}
}
程序的功能是将路径里面的 \\ 替换成 \\\\,因为存入数据库的时候 C:\\test.bmp这样的路径会出错,只有C:\\\\test.bmp才能正确的存入和取出。所以我写这个函数将\\换成\\\\,但是不知道哪里错了。请指教!C路径\\转\\\\求大神
#include <string.h>
#include <locale.h>
char s[256];
char *p;
int r,n,i;
int main() {
setlocale(LC_ALL,"chs");
while (1) {
printf("请输入一行文字(空行结束),\"%%20\"将替换为\" \",\"你懂得\"将替换为\"XXXXXX\":\n");
fgets(s,256,stdin);
if ('\n'==s[0]) break;
p=s;
while (1) {
p=strstr(p,"%20");
if (p) {
memmove(p+1,p+3,strlen(p)-3+1);
p[0]=' ';
} else break;
}
p=s;
while (1) {
p=strstr(p,"你懂得");
if (p) {
memmove(p+6,p+6,strlen(p)-6+1);
for (i=0;i<6;i++) p[i]='X';
} else break;
}
printf("%s",s);
}
return 0;
}
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//abcdefg%20helloworld%20something.pdf
//abcdefg helloworld something.pdf
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//这是测试文字你懂得,在这个你懂的地方,就得做你懂得的事
//这是测试文字XXXXX,在这个你懂的地方,就得做XXXXX的事
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//