Sign in to follow this  

problem with space

This topic is 4214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all. first of all i wanted to thank that guy who helped me in the other thread. its working now but i got a new problem. after i get a certian path (for ex c:/bc/a.ff) everything is ok but if i get a path with space there are starting to be problems (like tha path: c:/a b c/a.ff) so.. i know how to fix this.. i'll go with a loop over the char array and change the " " to somthing else. the problem is.. what should i change this to? somthing with %20 i think but i have no idea. can anyone help me with this? thanks in advance p.s if anyone is wondering what i am doing then... i'm trying to play with MCI the file that have been dragged to my window.. the problem is that mcisendstring cant have a space(" ") becuase he thinks i finished with the file and now i say his type or somthing... so that is the problem. [Edited by - mc30900 on July 4, 2006 1:50:54 PM]

Share this post


Link to post
Share on other sites
Im assuming you mean you are getting the path correctly but you are trying to do something with the path (execute it?) and its not working because of the spaces...

If thats the case then you have to wrap the path in double quotes before you can use it.

"C:\my docs\a.exe" //this works
C:\my docs\a.exe //this doesnt work

Share this post


Link to post
Share on other sites
Quote:
Original post by ju2wheels
Im assuming you mean you are getting the path correctly but you are trying to do something with the path (execute it?) and its not working because of the spaces...

If thats the case then you have to wrap the path in double quotes before you can use it.

"C:\my docs\a.exe" //this works
C:\my docs\a.exe //this doesnt work


i'll give u example whats going on with my program.
i'm trying to do somthing like this

char open[] = "open C:/a b/d.mp3" ;
mciSendString(open, NULL, 0, NULL);



the problem is.. that windows think that the " " between a and b
mean thats there are 3 parts in this string and not only 2.
so i cant use the full path.
i tried what u said but i cant compile it now :

char open[] = "open "C:/a b/d.mp3"" ;



what should i do?
thanks in advance

Share this post


Link to post
Share on other sites

char path[] = "\"C:/a b/d.mp3\"" ;




I dont know what your mciSendString is doing so if your really need to add "open" to the string then just put it before the first backslash....

escape characters

Share this post


Link to post
Share on other sites
-edited- look at my next msg

[Edited by - mc30900 on July 4, 2006 3:19:33 PM]

Share this post


Link to post
Share on other sites
strcpy(p, "\"");
strcat(p, path);
strcat(p, "\""); <-----

strcpy(open, "open ");
strcat(open,p);

That said, is this C or C++?

To understand why the backslash is there, ask yourself: how would you add a quote (") character to a string? String literals in C/C++ are represented by a pair of quotes with characters between them, so just putting a quote between two other quotes will "close" the string literal prematurely:
 The string stops here
|

"This is "a string""

So you have an escape character, which happens to be the backslash character (\). If you want to have a quote in a string, the you would use \" instead of just ".
The above would therefore be:

"This is \"a string\""

I hope this isn't too confusing.


jfl.

Share this post


Link to post
Share on other sites
yeah, i've just noticed a minute ago that i need another backslash.
i changed it and now it works!!
thanks guys!

Share this post


Link to post
Share on other sites

This topic is 4214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this