Solved

Converting \ to \\

Posted on 1998-06-11
16
269 Views
Last Modified: 2010-04-01
Ok, no i've got my win95 directory in a buffer and now I need to convert the \ in the path to \\ .... how ?
0
Comment
Question by:sbartok
  • 8
  • 7
16 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1165685
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165686
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;
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165687
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:sbartok
ID: 1165688
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 :-)
0
 
LVL 1

Author Comment

by:sbartok
ID: 1165689
The answer was correct ! exactly what i needed !
0
 
LVL 1

Author Comment

by:sbartok
ID: 1165690
The answer was correct ! exactly what i needed !
0
 
LVL 22

Accepted Solution

by:
nietod earned 10 total points
ID: 1165691
That is C++ code it will work in MFC or non MFC.

My e-mail is

nietod@theshop.net

but you can post comments here if you have questions or problems.  I usually use e-mail only if information is too long to post here.  (Like whole programs.)  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165692
An exclamation point?  As if it is a suprise that it works.  Now my feelings are hurt. :-)
0
 
LVL 1

Author Comment

by:sbartok
ID: 1165693
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 )

0
 
LVL 1

Author Comment

by:sbartok
ID: 1165694
my email is sacha@dillingen.baynet.de
0
 
LVL 1

Author Comment

by:sbartok
ID: 1165695
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,128);
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\CopyManager\CopyManagerDlg.cpp(208) : error C2065: 'DstChr' : undeclared identifier
E:\Applications\CopyManager\CopyManagerDlg.cpp(208) : error C2100: illegal indirection
E:\Applications\CopyManager\CopyManagerDlg.cpp(208) : error C2106: '=' : left operand must be l-value
E:\Applications\CopyManager\CopyManagerDlg.cpp(210) : error C2100: illegal indirection
E:\Applications\CopyManager\CopyManagerDlg.cpp(210) : error C2106: '=' : left operand must be l-value

any idea ?


0
 
LVL 1

Author Comment

by:sbartok
ID: 1165696
please send me the code per e@mail. thanx
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165697
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,128);
     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.  
0
 

Expert Comment

by:dj1encore
ID: 1165698
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1165699
You know, this was answered about 6 months ago.
0
 
LVL 1

Author Comment

by:sbartok
ID: 1165700
cool guys, thanx anyway :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question