|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
|
||||
|
||||
|
... 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? |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
||||
|
||||
|
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 11:00 AM. |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||
|
|||
|
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.
|
|
#7
|
||||
|
||||
|
Really? I'm gonna check it out.
If you're right, OMG! I can't believe I didn't try that. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > replacing things on a string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|