#1
  1. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13

    replacing things on a string


    I have a char array like so:
    char path[275]={0};
    in the array, I have this string:
    c:\test\other
    I want to change that string to:
    c:\\test\\other
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Representin' Quebec
    Posts
    106
    Rep Power
    12
    ... I don't get what you are trying to say! You put: "char path[275]={0}; " First of all (unless 0 means something else) '\0' is the null character. And why initialize it? And if you want to enter your own filename at runtime do like this:

    char path[275];
    cin.getline(path, 274, '\n');
    // 274 to leave space for the null character at the end...

    Do you understand this?
  4. #3
  5. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    Sorry about that. I'm not been very descriptive

    the first thing I'm doing is initializing the array so that it doesn't contain garbage. I like initializing my arrays.

    The string that it contains comes from a text file. I want to use that string as a file name for functions such as FindFirstFile(); however, as we know, if you pass functions an string like this:
    c:\test\other
    it will be no good as we have to scape our backlash. So, I already have the string, what i need is a function/method to turn the string c:\test\other that is contained in path[] to c:\\test\\other so that I could use it the above named functions.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Representin' Quebec
    Posts
    106
    Rep Power
    12
    Can't you just open your textfile and change it?

    But I have an alternative... Make a header file! (Do you know how?)
    Last edited by #define Gangsta; July 10th, 2003 at 10:00 AM.
  8. #5
  9. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    That's all basic stuff... How would a header file help, though?
    I need to do what I'm asking from within the app. The text file is a configuration file for a program that I'm making.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    18
    If the '\' character is already in the character array you don't need to escape it. You only need to do that if you use it in a string literal.
  12. #7
  13. pogremar
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    At Work
    Posts
    958
    Rep Power
    13
    Really? I'm gonna check it out.
    If you're right, OMG!
    I can't believe I didn't try that.

IMN logo majestic logo threadwatch logo seochat tools logo