user3622460 user3622460 - 11 months ago 75
C Question

How can I change the \ character in a string to the / character?

I'm using GetFullPathName and WinExec.

For WinExec to call my external program properly I need to have a full path to the program.

GetFullPathName() returns the following...

C:\job\curr01\help\hlp.exe


When I use this path in WinExec, nothing happens. This is because WinExec is expecting...

C:/job/curr01/help/hlp.exe


I know this because if I hard code the string "C:/job/curr01/help/hlp.exe" into WinExec() it works just fine and opens the program.

My question is how can I scan my string for '\' and replace them with '/'?

'\' I a special character and the following does not work...

below helpPath = 'C:\job\curr01\help\hlp.exe'

for (char* p = helpPath; p = strchr(p, "\"); ++p) {
*p = "/";
}


C has a problem with "\" because its a special character. I tried ""\"" and "//" but nothing seems to work.

Answer Source

Try this:

if (*p == '\\') // Here you escape the character '\'
    *p = '/';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download