sbartok
asked on
Converting \ to \\
Ok, no i've got my win95 directory in a buffer and now I need to convert the \ in the path to \\ .... how ?
answer coming.
I assume you want to convert all the slashes to double slashes. If not let me know.
The followig copies a string from Src to Dst and converts ever single slash to a double slash.
char Src[128]; // Buffer with single slash string.
char Dst[128]; // Buffer to receive double slash string.
const char *SrcPtr = Src;
char *DstPtr = Dst;
while(true)
{
char CurChr = *SrcPtr++;
*DstChr++ = CurChr;
if (DstChr == '\\') // If character was a slash, then
*DstChr++ = CurChr; // Output another slash.
else if (!CurChr) // If at end of string, then
break;
}
The followig copies a string from Src to Dst and converts ever single slash to a double slash.
char Src[128]; // Buffer with single slash string.
char Dst[128]; // Buffer to receive double slash string.
const char *SrcPtr = Src;
char *DstPtr = Dst;
while(true)
{
char CurChr = *SrcPtr++;
*DstChr++ = CurChr;
if (DstChr == '\\') // If character was a slash, then
*DstChr++ = CurChr; // Output another slash.
else if (!CurChr) // If at end of string, then
break;
}
Was wrong with that? If you don't like or don't understand an answer you should add a comment so that it is clear to the expert (and other experts) what the problem is.
ASKER
Thank you, (note : this is a mfc app) i'll try this.
could you give me your email if i have any ?s ?
would be cool !
if you write it as a answer again, you get 10 points :-)
could you give me your email if i have any ?s ?
would be cool !
if you write it as a answer again, you get 10 points :-)
ASKER
The answer was correct ! exactly what i needed !
ASKER
The answer was correct ! exactly what i needed !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
An exclamation point? As if it is a suprise that it works. Now my feelings are hurt. :-)
ASKER
Ok,
yeah, i know about mcf/c++ relations :-) i just wanted to tell you.
i also understand your email stuff (boy, i get abour 20messages per day )
yeah, i know about mcf/c++ relations :-) i just wanted to tell you.
i also understand your email stuff (boy, i get abour 20messages per day )
ASKER
my email is sacha@dillingen.baynet.de
ASKER
hmm, it doesn't work...
my code looks like :
char Src[128]; // Buffer with single slash string.
char Dst[128]; // Buffer to receive double slash string.
GetWindowsDirectory(Src,12 8);
const char *SrcPtr = Src;
char *DstPtr = Dst;
while(true)
{
char CurChr = *SrcPtr++;
/*line 208*/ *DstChr++ = CurChr;
if (DstChr == '\\') // If character was a slash, then
/*line 210*/ *DstChr++ = CurChr; // Output another slash.
else if (!CurChr) // If at end of string, then
break;
}
and i get the following compiler errors :
E:\Applications\CopyManage r\CopyMana gerDlg.cpp (208) : error C2065: 'DstChr' : undeclared identifier
E:\Applications\CopyManage r\CopyMana gerDlg.cpp (208) : error C2100: illegal indirection
E:\Applications\CopyManage r\CopyMana gerDlg.cpp (208) : error C2106: '=' : left operand must be l-value
E:\Applications\CopyManage r\CopyMana gerDlg.cpp (210) : error C2100: illegal indirection
E:\Applications\CopyManage r\CopyMana gerDlg.cpp (210) : error C2106: '=' : left operand must be l-value
any idea ?
my code looks like :
char Src[128]; // Buffer with single slash string.
char Dst[128]; // Buffer to receive double slash string.
GetWindowsDirectory(Src,12
const char *SrcPtr = Src;
char *DstPtr = Dst;
while(true)
{
char CurChr = *SrcPtr++;
/*line 208*/ *DstChr++ = CurChr;
if (DstChr == '\\') // If character was a slash, then
/*line 210*/ *DstChr++ = CurChr; // Output another slash.
else if (!CurChr) // If at end of string, then
break;
}
and i get the following compiler errors :
E:\Applications\CopyManage
E:\Applications\CopyManage
E:\Applications\CopyManage
E:\Applications\CopyManage
E:\Applications\CopyManage
any idea ?
ASKER
please send me the code per e@mail. thanx
There were a few typos. Try this.
char Src[128]; // Buffer with single slash string.
char Dst[128]; // Buffer to receive double slash string.
GetWindowsDirectory(Src,12 8);
const char *SrcPtr = Src;
char *DstPtr = Dst;
while(true)
{
char CurChr = *SrcPtr++;
*DstPtr++ = CurChr; /// changed
if (CurChr == '\\') // If character was a slash, then /// changed
*DstPtr++ = CurChr; // Output another slash. //// changed
else if (!CurChr) // If at end of string, then
break;
}
I marked the lines that were changed. If it okay with you, I prefer to post the correct information here. That way there is a permenant record for EE. I only use e-mail in extreme cases.
char Src[128]; // Buffer with single slash string.
char Dst[128]; // Buffer to receive double slash string.
GetWindowsDirectory(Src,12
const char *SrcPtr = Src;
char *DstPtr = Dst;
while(true)
{
char CurChr = *SrcPtr++;
*DstPtr++ = CurChr; /// changed
if (CurChr == '\\') // If character was a slash, then /// changed
*DstPtr++ = CurChr; // Output another slash. //// changed
else if (!CurChr) // If at end of string, then
break;
}
I marked the lines that were changed. If it okay with you, I prefer to post the correct information here. That way there is a permenant record for EE. I only use e-mail in extreme cases.
Search for the ascii value of "\" then place another into the string behind it. this workes well when asking for a path from the user, strcmp or step over the string using a pointer increment.
You know, this was answered about 6 months ago.
ASKER
cool guys, thanx anyway :-)