Thread: format specifier (precision) in strings

  1. #1
    Day Dreamer
    Join Date
    Apr 2007
    Posts
    45

    format specifier (precision) in strings

    I was getting confused over the use of precision format specifiers for strings.
    Like we use
    printf("%4.2d",somevar);
    to talk about decimal places,
    what does it mean in case of a string as in
    what does
    printf("%4.2s",somestringvar);
    mean?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by zombiezparadize View Post
    what does it mean in case of a string as in
    what does
    printf("%4.2s",somestringvar);
    mean?
    It means nothing. Strings don't have decimal points.

    EDIT: Oops, I was wrong. The precision specifies the maximum number of characters to print. The left hand side is the minimum number of characters to print (any fewer characters than this will print padding)
    Last edited by brewbuck; 06-12-2007 at 10:57 AM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  2. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  3. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 11:47 PM
  4. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  5. Table mapping Strings to Strings
    By johnmcg in forum C Programming
    Replies: 4
    Last Post: 09-05-2003, 11:04 AM