yellow flash Posted April 8, 2013 Share Posted April 8, 2013 so im trying to send values from c++ program to php in url i can send 1 value in url but when i try send second value in same url it doesnt work since i cant do '&' in sprintf anyone ever hade this problem or got some solutions would appriciate sprintf(start,"START %s %s?temp=%s[AMPERSAND HERE]min=%s",browser,site,temp,min); Quote Link to comment Share on other sites More sharing options...
rolf Posted April 8, 2013 Share Posted April 8, 2013 You probably need to give more information, because this works for me. Visual Studio 2010 Ultimate. #include <cstdio> using namespace std; int main(int argc, char*argv[]) { char start[2000]; char browser[] = "internetexplorer.exe"; char site[] = "fearleass-assassins.com"; char temp[] = "yes"; char min[] = "no"; sprintf(start,"START %s %s?temp=%s&min=%s",browser,site,temp,min); printf("%s", start); getchar(); return 0; } And you probably need to align it yourself, cause IP.boards is f#$chikng this up, but it works. Are you using strings? Quote Link to comment Share on other sites More sharing options...
rolf Posted April 8, 2013 Share Posted April 8, 2013 (edited) And also under Linux btw. [edit] This shouldn't be a doublepost Edited April 8, 2013 by rolf Quote Link to comment Share on other sites More sharing options...
yellow flash Posted April 8, 2013 Author Share Posted April 8, 2013 no char's Quote Link to comment Share on other sites More sharing options...
rolf Posted April 8, 2013 Share Posted April 8, 2013 No problem. You just discovered why strings suck. Anyway, the easy solution is to not use sprintf. Every string can be constructed using "+". E.g. #include <string> #include <iostream> using namespace std; int main(int argc, char*argv[]) { string start; string browser = "internetexplorer.exe"; string site = "fearleass-assassins.com"; string temp = "yes"; int min = -3; //sprintf(start,"START %s %s?temp=%s&min=%s",browser,site,temp,min); start = "START " + browser + " " + site + "?temp=" + temp + "&" + to_string((long double)min); cout << start << endl; getchar(); return 0; } Of course you get problems once you discover that an integer cannot be represented as a string (e.g string start = "a" + 1), but you can solve that as in the example code. Quote Link to comment Share on other sites More sharing options...
yellow flash Posted April 8, 2013 Author Share Posted April 8, 2013 k thanks rolf gonna try that tomorrow and let you know how it works out Quote Link to comment Share on other sites More sharing options...
yellow flash Posted April 12, 2013 Author Share Posted April 12, 2013 after thinking this hard we realized that since we started the browser on cmd line and ofc command line didnot understand '&' coz its command on it and we needed it to go thru as only symbol so it worked when we did this ^& and we used windows so i think '&' work's on linux as symbol only but yeah thanks for effort rolf Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.