what does printf("%2d",x) mean

Discussion in 'Mac Programming' started by dukebound85, Oct 26, 2006.

  1. dukebound85 macrumors P6

    dukebound85

    Joined:
    Jul 17, 2005
    Location:
    5045 feet above sea level
    #1
    i know what everything in the function does except for the 2. what exactly does the 2 do when printing the integer to the screen?
    i know with a float, it contols the decimal places but with an integer i have no idea

    or a 3? i have seen %3d as well while i am studying for my exam tomorrow


    thanks!
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    man printf

    B
     
  3. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #3
    Code:
         example% printf "%5d%4d\n" 1 21 321 4321 54321
    
         produces:
    
             1  21
           3214321
         54321   0
     
  4. bbarnhart macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #4
    "Minimum number of characters to be printed. If the value to be printed is shorter than this number the result is padded with blanks. The value is never truncated even if the result is larger."

    http://www.cplusplus.com/ref/cstdio/printf.html
     

Share This Page