Jump to content

c++ '&' sprintf


yellow flash

Recommended Posts

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);

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.