Jump to content

Is there an easy way of doing this??


Recommended Posts

Guest Croccy22
Posted

Is there an easy way of fixing the length of a string and pad it out with zeros??

I have an integer variable called Score but if the score is say 5 then I want it to display 000005, if it is 999 then display 000999 etc.

Is there an easy way of doind this. I have got around it at the moment with a few if statements but it looks untidy and I want to optimise it a bit.

Any solutions greatly accepted.

Thanx

Matt.

PS Smartanoids getting closer! (How many times have I said that before?)

Guest Arisme
Posted

sprintf(display_string, "%.6d", score); will do that nicely :wink:

Guest Croccy22
Posted

Thanx alot m8.

It's always the simple things that seem most complicated!!!

Matt

  • 2 weeks later...
Guest Zorglub
Posted
sprintf(display_string, "%.6d", score); will do that nicely  :wink:

Are you sure about this? I would have thought it was something like

sprintf(display_string, "%06d", score);

The . is used like for example: %.6f to say that you want to have six decimals. But then again I dont have my K&R with me right now :lol:

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.