format specifier (precision) in strings

This is a discussion on format specifier (precision) in strings within the C Programming forums, part of the General Programming Boards category; I was getting confused over the use of precision format specifiers for strings. Like we use printf("%4.2d",somevar); to talk about ...

  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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    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 11:57 AM.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 04: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, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21