Thread: Did I misunderstand any printf modifiers?

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617

    Did I misunderstand any printf modifiers?

    So far this is how I'm treating the modifiers in my custom implementation:

    Code:
    /* Defaults used if %> is not used to switch to another set
     *
     * In all cases these modifiers are read directly instead of via callbacks:
     *
     * + Same as standard printf definition, forces a sign for numbers
     * - Same as standard printf definition, left justifies output
     * # Same as standard printf definition, applies prefix, for numbers it's the
     *   usual 0x0, 0b0, 00 etc, for strings it's instead L", u8" etc, similar for
     *   characters: L', u', U' etc
     * ! Applies suffix, for numbers this means ULL etc, for strings it's just ",
     *   for characters it's just '
     * ? Where conversions of character encoding need to be done, if a character
     *   that cannot be converted appears, this character is substituted, expects
     *   a pawd (int) which is then stored in a pawc (char, PAWVA_DATA->sub)
     * . Indicates precision is to be read in from that point onwards
     * * Prior to the . character indicates minimum characters to output, after the
     *   . character indicates the number of digits after the decimal . to output
     * */
    >, ! and ? are my own additions obviously, the only one I'm feel is wrong is the * modifier

  2. #2
    Registered User
    Join Date
    Sep 2020
    Posts
    344
    '*' after the decimal applies a little differently to strings.

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617
    Quote Originally Posted by hamster_nz View Post
    '*' after the decimal applies a little differently to strings.
    I haven't been able to find information on that, yet I vaguely remember reading somewhere it meant the length of the passed string, is that correct?

  4. #4
    Registered User
    Join Date
    Sep 2020
    Posts
    344
    Look under "Precision" in printf(3) - Linux manual page for a full description.

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,617
    Quote Originally Posted by hamster_nz View Post
    Look under "Precision" in printf(3) - Linux manual page for a full description.
    ty, wish I'd though of the linux man pages, oh well, at least I now have a lot more info I didn't have before

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access Modifiers
    By DavidP in forum C# Programming
    Replies: 2
    Last Post: 05-21-2008, 09:19 AM
  2. typedef modifiers
    By SKeane in forum C Programming
    Replies: 1
    Last Post: 09-26-2006, 05:06 AM
  3. help with using printf()
    By jcasale in forum C Programming
    Replies: 12
    Last Post: 02-09-2005, 05:50 PM
  4. make printf using printf?
    By germaneater in forum C Programming
    Replies: 9
    Last Post: 11-10-2004, 10:58 PM
  5. Bad printf()!
    By kirby1024 in forum C Programming
    Replies: 2
    Last Post: 06-02-2002, 09:24 AM

Tags for this Thread