Thread: fprintf & nth argument conversion

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    fprintf & nth argument conversion

    I've tried using nth argument conversion specifiers as mentioned here:
    Conversions can be applied to the nth argument after the format in the argument list, rather than to the next unused argument. In this case, the conversion specifier character % (see below) is replaced by the sequence "%n$", where n is a decimal integer in the range [1,{NL_ARGMAX}], giving the position of the argument in the argument list. This feature provides for the definition of format strings that select arguments in an order appropriate to specific languages (see the EXAMPLES section).
    But I can't seem to get it work (i.e. I use "%1$s", and fprintf prints "$s"...).
    My compiler is capable of handling ISO C (I'm using MingW) so I would hope that XSI exstensions would notbe a problem.
    How can I get my compiler to support this (i.e. any flags/packages/updates for MingW for this?).

    p.s. apparently you cant even put anything that even remotely resembles code into quote tags... this is getting ridiculous
    feel free to join my silent protest with the awesome power of super-elongated horizontal scroll bars.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The problem is that MinGW is reliant on the Microsoft runtime library for much of its support.

    So for the same reason that you need to use %I64 rather than %lld when printing long long values, you may find support for XSI limited or non existant.

    This works in cygwin for example
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(){
        printf("%2$s %1$s\n", "hello", "world" );
        return 0;
    }
    
    $ gcc -W -Wall foo.c
    $ ./a.exe
    world hello
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 06:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 09:44 PM