Thread: double backslashes

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    4

    double backslashes

    Ok so I have a file path i got from findfirstfile. I need to replace all the single backslashes with double backslashes correct? What is the best way to do that?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Replacing them with forward slashes would be easier. An unoptomized example:
    Code:
    {
      char *p;
    
      while((p = strchr(path, '\\')))
        *p = '/';
    }
    If you understand what you're doing, you're not learning anything.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Grunt12
    Ok so I have a file path i got from findfirstfile. I need to replace all the single backslashes with double backslashes correct?
    No. Escaping backslashes like this is only something you need to do to string literals in source code.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    4
    oh, so if i am writing it in code, i have to escape it, but if I get the path from an api function I dont.

  5. #5
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    That is correct. The difference is that the compiler treats backslash as a special character (a character escape), but the runtime environment does not. Paths received from API funcions are not seen by the compiler.
    Insert obnoxious but pithy remark here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  2. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  3. need some help with last part of arrays
    By Lince in forum C Programming
    Replies: 3
    Last Post: 11-18-2006, 09:13 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM