September 2nd, 2003, 11:39 AM
strcat, any other way to join strings?
is there another way to join strings than strcat, sort of like phps
basically i have a string parameter for a function, but i want to send it like
function("Asdsadsa" + MYVARIABLE + "ASDSADS");
but that of course doesnt work, at least not for me. Im pretty knew so please lend me your wisdom :D
September 2nd, 2003, 12:00 PM
You can use sprintf or wsprintf, but I think strcat is more simple, this is in C. I think C++ has another way.
sprintf(buffer, "Asdsadsa%sASDSADS", yourStringVar);
%d for int
September 2nd, 2003, 12:22 PM
If you're using C++, the string class has the + operator overloaded to concatenate strings. You can also use the c_str() method to return a char * to your function. So you could cast the first item to class string, use the + operator and finally call the c_str() method to convert it back to char *. The code could go something like this:
function((string("Asdsadsa") + MYVARIABLE + "ASDSADS").c_str());
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
September 2nd, 2003, 12:25 PM
great, thats exactly what i was looking for. Thanks Scorpion