Guest Croccy22 Posted March 29, 2003 Report Share Posted March 29, 2003 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?) Link to comment Share on other sites More sharing options...
Guest Arisme Posted March 29, 2003 Report Share Posted March 29, 2003 sprintf(display_string, "%.6d", score); will do that nicely :wink: Link to comment Share on other sites More sharing options...
Guest Croccy22 Posted March 29, 2003 Report Share Posted March 29, 2003 Thanx alot m8. It's always the simple things that seem most complicated!!! Matt Link to comment Share on other sites More sharing options...
Guest midnight Posted March 29, 2003 Report Share Posted March 29, 2003 bit like my brain :wink: Link to comment Share on other sites More sharing options...
Guest Zorglub Posted April 6, 2003 Report Share Posted April 6, 2003 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: Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now