C语言中如何将字符串中的'\'变成'\\'?
现有字符串
E:\myvc\HHH.txt
如何将里面的 '\ '变成 '\\ '?最后要得到 E:\\myvc\\HHH.txt
[解决办法]
如果是要做机器转换字符串的话,可以用
#include <conio.h>
#include <stdio.h>
#include <string.h>
void main()
{
char *s= "e:\\myvc\\HHH.txt ";
char *p,*l = s;
char d[100],*pd = d;
while ( (p = strchr(l, '\\ ')) != NULL)
{
strncpy(pd,l,p-l);
pd += (int)(p-l);
*pd++ = '\\ ';
*pd++ = '\\ ';
l = p + 1;
}
strcpy(pd,l);
printf( "%s ",d);
getch();
}