Trouble with char* concatenation using SDL

My problem is that there is a function I need to use from the SDL library. I have to pass a message of type const char* usually like this


I need a way to concatenate the original message with a char* array I have set up for example


I would even like to create the message then add the array element onto it but it says I can't do it since they have to be constant.

Sorry if this doesn't make sense but I have tried to make it as simple as I can, Thanks.
Don't use char arrays unless you have to. Use strings.
When you need to pass the string to a function that takes a const char*, use the c_str member:

string array[10] = { "whatever", "foo", "bar", "blah" };

string msg = "message" + array[1];

function( msg.c_str() );  // <- to "convert" to const char* 

Of if you want, you can remove the 'msg' temp variable:
function( ("message" + array[1]).c_str() ); // <- legal as long as array[1] is a string 

Secondly... please tell me you are not using SDL 1.2. It is horribly ancient and outdated.
Last edited on
Ok thanks for that I will give it a try now and sadly yes I'm planning on making space invaders since I'm pretty new to the gui stuff, what would you recommend I use instead? OpenGL?
I like SFML.

But There's a more modern version of SDL ("SDL HG" or "SDL 2.0") which supposedly fixes the problems with SDL 1.2.

Anyway... SDL 1.2 will work... it just gets crap performance, is severely limited/crippled, and uses extremely outdated drawing concepts.
Topic archived. No new replies allowed.