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