Sign in to follow this  

Output variable values

Recommended Posts

I have a quick question, i'm using the extension lib sdl_ttf to input the player1 and player2 score. The variables are global and defined right below the includes so they're acessable over the whole program. The score system is working fine but the output of the score is not going so well. When i'm using: sprintf(score, "Player 1: %0.f", player1Score); p2score = TTF_RenderText_Solid(font, score, fontColor); It somehow picks up that the player1Score is an int but not the value itself. Is there any other way to store the value in a variable than using sprintf if you're going to use both a string and a int in the same string?

Share this post

Link to post
Share on other sites
Original post by password
I see, I didn't know that, I thought it was some kind of temporary holder for the variable, thank you.

It tells sprintf where to embed the value in the string.

BTW, if you are using c++ I highly recommend you use std::string for text and std::stringstream for this sort of conversion.

#include <string>
#include <sstream>

std::string score = "Player 1: ";
std::stringstream scorestream;
scorestream << player1Score;
score += scorestream.str();

p2score = TTF_RenderText_Solid(font, score.c_str() , fontColor);

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this