Sign in to follow this  

displaying second in the right format

Recommended Posts

Hi there I have being working on my first game. it is really simple but I am have trouble display the seconds in the correct way ie if DISPLAY_SECOND <= 9 print "0" + DISPLAY_SECOND else print DISPLAY_SECOND
    char Buffer[255]; 
    sprintf(Buffer, "Time Taken: %d:%d ",CURRENT_SECONDS/60,DISPLAY_SECONDS);
    text.drawText(game->screen, Buffer, small_font, 255, 255, 255, 5, 2);
but I am unsure on how to manipulate the string thanks for your time hope you can help ian :)

Share this post

Link to post
Share on other sites
I humbly propose this as an even better solution: ;)

char buffer[255];
int mins = current_seconds/60;
int secs = current_seconds%60;
snprintf(buffer, sizeof(buffer), "Time %02d:%02d", mins, secs);

The calculation of the seconds looks nicer and a potential buffer overflow was avoided. Still not good with negative values for current_seconds.

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