Problem with strings

Started by
2 comments, last by Trienco 10 years, 9 months ago
I've been working on an awesomium app, and have run into a bit of a problem with strings.
Here's an example
int currentconfig = configsHandle->currentConfig;
char gamedir[260];
//_snprintf(gamedir, sizeof(gamedir),"$('#gamedata0').val('%s');",configsHandle->m_Configs[currentconfig]->m_gamedir);
_snprintf(gamedir, sizeof(gamedir),"$('#gamedata0').val('%s');","f:\\\\what\\\\the\\\\f#$&.fgd");
//printf("the gamedir is: %s\n",gamedir);
MessageBoxA(0,gamedir,"message",MB_OK);
caller->ExecuteJavascript(WSLit(gamedir),WSLit(""));
My problem is this, f:\\\\what\\\\the\\\\f#$&.fgd evaluates to f:\\what\\the\\f#$&.fgd for the messagebox, while on the html element #gamedata0 it shows up as f:\what\the\f#$&.fgd

How would i go about getting configsHandle->m_Configs[currentconfig]->m_gamedir converted to something that will show up correctly in the html?
Advertisement

Since 4 slashes translates to 2 in what looks like C (or C++), and then translates to 1 in HTML, perhaps it is because storing in gamedir stores 2 slashes next to each other instead of 4 because the slash is an escape character, and when passed along, it looks like second escape set, so it escapes it again.

\\\\ -> \\
\\ -> \
Thanks, that verifies what I was thinking. Earlier this morning I figured that I should use a function to replace all "\\" with "\\\\". A quick google search came up with this http://stackoverflow.com/questions/779875/what-is-the-function-to-replace-string-in-c and it worked perfectly

Which is why a / should be used as a path separator whenever possible (yes, even on Windows). There are extremely few cases where it won't work.

f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement