[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Converting \ to \\

Posted on 1998-06-11
16
Medium Priority
?
277 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 40 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

825 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