# problem with space

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

## 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 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 on other sites
Quote:
 Original post by ju2wheelsIm 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 worksC:\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?

##### 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 on other sites
-edited- look at my next msg

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

##### Share on other sites
-edited-
nvm it works!!!!!!!! thanks a lot

##### Share on other sites
your second strcat is missing a backslash...

##### 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 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!

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013295
×