Thread: Number of digits?

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    2

    Number of digits?

    Excuse the newbie question but I haven't been able to find an answer to my problem. Most questions I can find on the net but I'm not sure what to search for this time.

    I have a small simple program I wrote that reads the number of seconds the system has been up and outputs 3 values; days, hours and minutes. The trouble is when any value is less than 10 only 1 digit is displayed and messes my formating. What I want to do is always output 2 digits so if a value is less than 10 it starts with a zero like '08'.

    Any help or pointers would be much appreciated.

    Thanks
    Last edited by falador; 05-13-2004 at 03:30 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    printf format specifiers. Specificly, look at the 0 and the "optional decimal digit" section.
    Code:
    printf( "%02", 3 );
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    2
    That did the trick, thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  2. Learning Memory, Ins and Outs?
    By Zoiked in forum C Programming
    Replies: 1
    Last Post: 08-27-2007, 04:43 PM
  3. numeric header - number of digits
    By Mario F. in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2006, 12:02 PM
  4. Count the number of vowels, consonants, digits etc.
    By kumar14878 in forum C Programming
    Replies: 3
    Last Post: 05-09-2005, 12:34 AM
  5. Extracting individual digits from a short
    By G'n'R in forum C Programming
    Replies: 9
    Last Post: 08-30-2001, 10:30 AM