How to convert int to a const char?

Well I want to display message to my SDL program, and I want it to be an interger that keeps changing. Here's what I have offcourse its wrong somehow I have to get my scoreN to be const char.
1
2
3
4
5
6
int scoreN = 1;
SDL_Surface *Score = NULL;
Score = TTF_RenderText_Solid(
regfont, scoreN ,blackc);
SDL_BlitSurface(Score,NULL,screen,&cords);
SDL_FreeSurface(Score);

if I change scoreN in line 4 to a for example "Hello World" it would
be displayed.

Thanks a lot for posts and appreciate you help! :D
Last edited on
Here's an article on how to convert a number into a string: http://www.cplusplus.com/articles/numb_to_text/
( you can get a const char * from a std::string via c_str member function )
Hey Im still not sure how to do this, I got my int to string how do I make it const char with c_str?

heres what I have:
thanks ;D

1
2
3
4
5
6
7
8
9
10
11
12
   
int SCORE = 1;    
string scoreN;         
ostringstream convert;
convert << SCORE;
scoreN = convert.str(); 
   
     SDL_Surface *Score = NULL;
     Score = TTF_RenderText_Solid(
     regfont, scoreN ,blackc);
     SDL_BlitSurface(Score,NULL,screen,&cords);
     SDL_FreeSurface(Score);
This is what I added, and my program crashes, but didn't get any debug errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int SCORE = 1;    
string scoreN1;         
ostringstream convert;
convert << SCORE;
scoreN1 = convert.str(); 

const char * scoreN = scoreN1.c_str();

   
     SDL_Surface *Score = NULL;
     Score = TTF_RenderText_Solid(
     regfont, scoreN ,blackc);
     SDL_BlitSurface(Score,NULL,screen,&cords);
     SDL_FreeSurface(Score);

check whether TTF_RenderText_Solid succeeded and try TTF_GetError
http://jonatkins.org/SDL_ttf/SDL_ttf_12.html
actually this code works, I just put the whole thing in a loop. I had to move parts of it around and it works :D
Topic archived. No new replies allowed.