Solved

Converting \ to \\

Posted on 1998-06-11
16
263 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now