%n$ conversion specifications
Earlier we noted that the %n$ form of
conversion specification lets you convert the nth
argument in a printf or scanf
argument list rather than the next unused argument.
We showed you how you could use the feature
to control the format of the date and time
in different locales, and suggested that %n$
had a wider
application than that.
What we had in mind were cases in which the rules
of a given language were built into print statements such as
printf("%s %s\n",
func == MAP ? "Can't map" : "Can't create", pathname);
The problem with this code
is that it assumes that the verb precedes the object of the sentence,
which is not the case in many languages.
In other words, even if we rewrote the fragment to use gettxt,
and stored translations of the strings in
message files in the appropriate locales,
we would still want to use the %n$
conversion specification to switch the arguments
to printf depending on the locale.
That is, the printf format string
"%1$s %2$s\n"
in an English-language locale would be written
"%2$s %1$s\n"
in a locale in which the object of the sentence precedes the predicate.
Previous topic:
gencat and catgets (X/Open)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005