Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Hi
I want change one address like ( C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg) to valid address for use it in c++ code ...

I want use that address in some code like fopen();

pay attention I give that address from user and must change it in my programm

please help me.

thanks
Posted
Comments
Joan M 17-May-11 13:55pm    
Without more information the answer from Albert Holguin seems perfect. If it is solved, please mark it as solved accepting the solution... if it is not solved add more information.

PS: what Richard MacCutchan has posted is also nice and adds more information for you...

What do you mean by "must change it"? If the user types the address into a dialog or direct into cin or similar then there is nothing you need to do. A good alternative would be to use one of the Common Dialogs[^] and just let the user navigate to the required location.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-May-11 17:27pm    
Good point, a 5.
Please see my answer.
--SA
That is a valid address... only thing you have to remember is if you programatically specify the location through a string you have to use '\\' to indicate a backslash character (instead of a single slash) however if you bring in the address from some control that's usually already handled there:

CString location = "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg";
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-May-11 17:29pm    
This is correct (my 5), but any immediate (hard-coded) constants (by the way, you should have made it at least explicit constant) are practically pointless.

Please see my answer.
--SA
Albert Holguin 17-May-11 17:30pm    
pointless? true
Niklas L 18-May-11 11:48am    
"if you bring in the address from some control that's usually already handled there", a somewhat strange formulation, since escaping is done only for the compiler to understand it. Once your program run, you don't need to escape backslashes.
Albert Holguin 18-May-11 17:39pm    
yeah i guess its bad phrasing
There is not situations when the immediate string constant can be hard-coded in a software product code.
How can you maintain that? All paths should be calculated based on your executable file location and/or your configurations file(s).

(All other immediate constants should became explicit constants or go to resources.)

Alternatively, use file dialogs, as Richard suggested.

—SA
 
Share this answer
 
v4
Comments
Richard MacCutchan 18-May-11 3:08am    
More good advice and gets a 5; let's hope someone is listening. :)
Sergey Alexandrovich Kryukov 18-May-11 3:17am    
Thank you, Richard. Listening is apparently a very difficult thing, much harder than talking, if you look at the effect of all our advices... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900