user3325834
user3325834

Reputation:

C int print formatting problems

I'm trying to print out time in like

hours:mins:secs

so if it was 8am, 12 mins, 34 seconds have this

08:12:34

but I keep getting

8:12:34

or

_8:12:34

Is there a way to make sure there is a '0' in front?

Upvotes: 0

Views: 40

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 994629

Sure, use

%02d:%02d:%02d

as your printf format output. (You didn't say what output method you were using, so I am assuming stdio and printf.)

Upvotes: 3

Related Questions