Solved

Converting \ to \\

Posted on 1998-06-11
16
262 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

707 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

15 Experts available now in Live!

Get 1:1 Help Now