Thread: Noob printf question

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    183

    Noob printf question

    Hey i new to C i wanted to ask a noob printf question
    why sometimes in like for printing out character we do %.1d what that 1 before integer for ? i Tried looking it over what does it mean and i added like %.9d it added a couple of zeroes.
    thanks.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Lookup the printf() manpage; the 9 in %.9d is the precision which dictates the minimum number of digits that will appear in the output.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you use "%4d" then it means "print the number using 4 positions". "%5.4d" means "use 5 positions, and use digits for 4 of those", fill with zeros to make up missing digits, and spaces to make up the rest of the space.

    "%5.4d" used on the number 123 will give
    Code:
     0123
    as the output.
    If the number is more than 4 digits, it will print the entire number using as many digits as it needs.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    thanks alot dude i understand it now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Code Question
    By lyoncourt in forum C Programming
    Replies: 3
    Last Post: 09-16-2007, 04:33 PM
  4. noob question
    By gillypie in forum C Programming
    Replies: 21
    Last Post: 09-04-2007, 07:49 AM
  5. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 06:54 AM