Thread: help with c print specifiers

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    67

    help with c print specifiers

    Hi have a question for one of my homework. I need to explain what is going on the printf statement i have figure all of them except for this two.

    Code:
    line 6	printf("%*.*f", 7, 2, num);
    line 19	printf("%t%3f\n", num);
    lets say num = 26.536

    i know line 6 is the same as saying printf("7.2f"), but i looked on line but all the results i get are pointer declarations, etc.

    line 19 im confused since \t is an escape sequence for a hor. tab right. but is just prints "%3f"

    thanks for the help.
    Last edited by newbc; 02-25-2011 at 11:12 AM.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Line 6: You forgot the %.
    Line 19 The tab should be "\t". Not "%t"

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Line 6 will print *.*f and line 19 will print %3f because it doesn't understand your formatting setups...

    printf format identifiers.

    For the first line to print 7 2 26.536 you would need printf("%d %d %.3f",7,2,num);

    I'll let you figure the second one out on your own...

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    No. newbc is using variable width/precision specifier '*'.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nonoob View Post
    No. newbc is using variable width/precision specifier '*'.
    Ok... this is new to me... Gonna have to look this one up...
    (I spend most of my time working in windows and printf isn't a big part of my life)

  6. #6
    Registered User
    Join Date
    Nov 2010
    Posts
    67
    yes line six is suppose to include the % sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 02-19-2010, 07:50 PM
  2. Please help me as fast as possible
    By Xbox999 in forum C Programming
    Replies: 5
    Last Post: 11-30-2009, 06:53 PM
  3. Towr of Hanoi move the disc
    By WatchTower in forum C Programming
    Replies: 9
    Last Post: 07-17-2009, 03:48 AM
  4. Replies: 1
    Last Post: 07-31-2002, 11:35 AM
  5. How to print out the data throw printer.Attn Salem
    By Jason in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 05:58 AM