Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting \ to \\

Posted on 1998-06-11
16
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

636 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