tags:

views:

24

answers:

1
int score = 0;
char* fixedscore=(char*)score;
.
.
.
imgTxt = TTF_RenderText_Solid( font, fixedscore, fColor );

^^ This doesn't work - looks like fixedscore is empty or doesn't exists.

int score = 0;
char* fixedscore=(char*)score;
.
.
.
imgTxt = TTF_RenderText_Solid( font, "Works fine", fColor );

^^ Works fine, but...

I guess converting int to char* doesn't really work. So how do you print scores in SDL? Oh and one more thing: why is the text so ugly?

Any help would be appreciated. Thanks.

A: 

Casting is not what you want. This code:

int score = 0;
char* fixedscore=(char*)score;

is the equivalent of doing:

char* fixedscore = NULL;

I assume you are trying to get fixedscore to hold the textual value of the number in score. The easiest way using just standard C++ is via stringstream:

std::stringstream strm;
strm << score;

...

imgTxt = TTF_RenderText_Solid( font, strm.str().c_str(), fColor );
R Samuel Klatchko
COOL BEANS!! Thank you very very much. :)Had to add: #include <sstream>#include <string>using namespace std;But it's working now. Yay! Thanks again!
jack moore