1FWPRINTF(P)                POSIX Programmer's Manual               FWPRINTF(P)
2
3
4

NAME

6       fwprintf, swprintf, wprintf - print formatted wide-character output
7

SYNOPSIS

9       #include <stdio.h>
10       #include <wchar.h>
11
12       int  fwprintf(FILE  *restrict  stream,  const wchar_t *restrict format,
13       ...);
14       int swprintf(wchar_t *restrict ws, size_t n,
15              const wchar_t *restrict format, ...);
16       int wprintf(const wchar_t *restrict format, ...);
17
18

DESCRIPTION

20       The fwprintf() function shall place output on the named output  stream.
21       The wprintf() function shall place output on the standard output stream
22       stdout. The swprintf() function shall place output followed by the null
23       wide  character in consecutive wide characters starting at *ws; no more
24       than n wide characters shall be written, including a  terminating  null
25       wide character, which is always added (unless n is zero).
26
27       Each  of these functions shall convert, format, and print its arguments
28       under control of the format wide-character string.  The format is  com‐
29       posed  of  zero or more directives: ordinary wide-characters, which are
30       simply copied to the output stream, and conversion specifications, each
31       of which results in the fetching of zero or more arguments. The results
32       are undefined if there are insufficient arguments for the  format.   If
33       the  format  is  exhausted while arguments remain, the excess arguments
34       are evaluated but are otherwise ignored.
35
36       Conversions can be applied to the nth argument after the format in  the
37       argument  list,  rather than to the next unused argument. In this case,
38       the conversion specifier wide character % (see below)  is  replaced  by
39       the  sequence  "%n$"  ,  where  n  is  a  decimal  integer in the range
40       [1,{NL_ARGMAX}], giving the position of the argument  in  the  argument
41       list. This feature provides for the definition of format wide-character
42       strings that select arguments in an order appropriate to specific  lan‐
43       guages (see the EXAMPLES section).
44
45       The  format  can  contain either numbered argument specifications (that
46       is, "%n$" and "*m$"), or unnumbered argument conversion  specifications
47       (that  is,  % and * ), but not both. The only exception to this is that
48       %% can be mixed with the "%n$" form. The results of mixing numbered and
49       unnumbered  argument  specifications  in a format wide-character string
50       are undefined. When numbered argument specifications are used, specify‐
51       ing  the Nth argument requires that all the leading arguments, from the
52       first to the  (N-1)th,  are  specified  in  the  format  wide-character
53       string.
54
55       In  format  wide-character strings containing the "%n$" form of conver‐
56       sion specification, numbered arguments in the argument list can be ref‐
57       erenced  from  the  format  wide-character  string  as  many  times  as
58       required.
59
60       In format wide-character strings containing the %  form  of  conversion
61       specification, each argument in the argument list shall be used exactly
62       once.
63
64       All forms of the fwprintf() function  allow  for  the  insertion  of  a
65       locale-dependent  radix  character  in  the  output string, output as a
66       wide-character value. The radix character is defined in  the  program's
67       locale  (category  LC_NUMERIC  ).  In  the POSIX locale, or in a locale
68       where the radix character is not defined,  the  radix  character  shall
69       default to a period ( '.' ).
70
71       Each  conversion  specification is introduced by the '%' wide character
72        or by the wide-character sequence "%n$",   after which  the  following
73       appear in sequence:
74
75        * Zero  or  more flags (in any order), which modify the meaning of the
76          conversion specification.
77
78        * An optional minimum field width. If the converted  value  has  fewer
79          wide characters than the field width, it shall be padded with spaces
80          by default on the left; it shall be padded  on  the  right,  if  the
81          left-adjustment flag ( '-' ), described below, is given to the field
82          width. The field width takes the  form  of  an  asterisk  (  '*'  ),
83          described below, or a decimal integer.
84
85        * An  optional  precision  that  gives the minimum number of digits to
86          appear for the d , i , o , u , x , and X conversion specifiers;  the
87          number of digits to appear after the radix character for the a , A ,
88          e , E , f , and F conversion specifiers; the maximum number of  sig‐
89          nificant  digits for the g and G conversion specifiers; or the maxi‐
90          mum number of wide characters to be printed from a string in  the  s
91          conversion  specifiers.  The  precision takes the form of a period (
92          '.' ) followed either by an asterisk ( '*' ), described below, or an
93          optional  decimal digit string, where a null digit string is treated
94          as 0. If a precision appears with any other conversion wide  charac‐
95          ter, the behavior is undefined.
96
97        * An optional length modifier that specifies the size of the argument.
98
99        * A  conversion  specifier  wide  character that indicates the type of
100          conversion to be applied.
101
102       A field width, or precision, or both, may be indicated by an asterisk (
103       '*' ). In this case an argument of type int supplies the field width or
104       precision. Applications shall ensure that  arguments  specifying  field
105       width,  or precision, or both appear in that order before the argument,
106       if any, to be converted.  A negative field width is taken as a '-' flag
107       followed by a positive field width. A negative precision is taken as if
108       the precision were omitted.    In format  wide-character  strings  con‐
109       taining  the "%n$" form of a conversion specification, a field width or
110       precision may be indicated by the sequence "*m$", where m is a  decimal
111       integer  in  the range [1,{NL_ARGMAX}] giving the position in the argu‐
112       ment list (after the format argument) of an integer argument containing
113       the field width or precision, for example:
114
115
116              wprintf(L"%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);
117
118       The flag wide characters and their meanings are:
119
120       '      The integer portion of the result of a decimal conversion ( %i ,
121              %d , %u , %f , %F , %g , or %G ) shall be formatted  with  thou‐
122              sands'  grouping  wide  characters.  For  other conversions, the
123              behavior is undefined. The numeric grouping  wide  character  is
124              used.
125
126       -      The  result of the conversion shall be left-justified within the
127              field.  The conversion shall be right-justified if this flag  is
128              not specified.
129
130       +      The result of a signed conversion shall always begin with a sign
131              ( '+' or '-' ). The conversion shall begin with a sign only when
132              a negative value is converted if this flag is not specified.
133
134       <space>
135              If  the  first  wide  character  of a signed conversion is not a
136              sign, or if a signed conversion results in no wide characters, a
137              <space>  shall be prefixed to the result. This means that if the
138              <space> and '+' flags both appear, the  <space>  flag  shall  be
139              ignored.
140
141       #      Specifies  that  the  value is to be converted to an alternative
142              form.  For o conversion, it increases the precision  (if  neces‐
143              sary) to force the first digit of the result to be 0. For x or X
144              conversion specifiers, a non-zero result shall have 0x  (or  0X)
145              prefixed to it. For a , A , e , E , f , F , g , and G conversion
146              specifiers, the result shall always contain a  radix  character,
147              even  if no digits follow it. Without this flag, a radix charac‐
148              ter appears in the result of these conversions only if  a  digit
149              follows  it.  For  g and G conversion specifiers, trailing zeros
150              shall not be removed from the result as they normally  are.  For
151              other conversion specifiers, the behavior is undefined.
152
153       0      For  d  ,  i , o , u , x , X , a , A , e , E , f , F , g , and G
154              conversion specifiers, leading zeros (following  any  indication
155              of  sign  or  base) are used to pad to the field width; no space
156              padding is performed. If the '0' and '-' flags both appear,  the
157              '0' flag shall be ignored. For d , i , o , u , x , and X conver‐
158              sion specifiers, if a precision is specified, the '0' flag shall
159              be  ignored.  If  the '0' and '" flags both appear, the grouping
160              wide characters are inserted before zero padding. For other con‐
161              versions, the behavior is undefined.
162
163
164       The length modifiers and their meanings are:
165
166       hh     Specifies  that  a following d , i , o , u , x , or X conversion
167              specifier applies to a signed char  or  unsigned  char  argument
168              (the  argument  will have been promoted according to the integer
169              promotions, but its value shall be converted to signed  char  or
170              unsigned char before printing); or that a following n conversion
171              specifier applies to a pointer to a signed char argument.
172
173       h      Specifies that a following d , i , o , u , x , or  X  conversion
174              specifier  applies  to  a  short or unsigned short argument (the
175              argument will have been promoted according to the integer promo‐
176              tions,  but  its  value  shall be converted to short or unsigned
177              short before printing); or that a following n conversion  speci‐
178              fier applies to a pointer to a short argument.
179
180       l (ell)
181              Specifies  that  a following d , i , o , u , x , or X conversion
182              specifier applies to a long or unsigned long  argument;  that  a
183              following  n conversion specifier applies to a pointer to a long
184              argument; that a following c conversion specifier applies  to  a
185              wint_t argument; that a following s conversion specifier applies
186              to a pointer to a wchar_t argument; or has no effect on  a  fol‐
187              lowing a , A , e , E , f , F , g , or G conversion specifier.
188
189       ll (ell-ell)
190
191              Specifies  that  a following d , i , o , u , x , or X conversion
192              specifier applies to a long long or unsigned long long argument;
193              or  that a following n conversion specifier applies to a pointer
194              to a long long argument.
195
196       j      Specifies that a following d , i , o , u , x , or  X  conversion
197              specifier  applies to an intmax_t or uintmax_t argument; or that
198              a following n conversion specifier applies to a  pointer  to  an
199              intmax_t argument.
200
201       z      Specifies  that  a following d , i , o , u , x , or X conversion
202              specifier applies to a size_t or the corresponding signed  inte‐
203              ger  type  argument;  or that a following n conversion specifier
204              applies to a pointer to a signed integer type corresponding to a
205              size_t argument.
206
207       t      Specifies  that  a following d , i , o , u , x , or X conversion
208              specifier applies to a ptrdiff_t or the  corresponding  unsigned
209              type  argument;  or  that  a  following  n  conversion specifier
210              applies to a pointer to a ptrdiff_t argument.
211
212       L      Specifies that a following a , A , e , E , f , F , g , or G con‐
213              version specifier applies to a long double argument.
214
215
216       If  a  length modifier appears with any conversion specifier other than
217       as specified above, the behavior is undefined.
218
219       The conversion specifiers and their meanings are:
220
221       d, i   The int argument shall be converted to a signed decimal  in  the
222              style  "[-]dddd".  The precision specifies the minimum number of
223              digits to appear; if the value being  converted  can  be  repre‐
224              sented in fewer digits, it shall be expanded with leading zeros.
225              The default precision shall be 1. The result of converting  zero
226              with an explicit precision of zero shall be no wide characters.
227
228       o      The  unsigned argument shall be converted to unsigned octal for‐
229              mat in the style "dddd" . The precision  specifies  the  minimum
230              number  of digits to appear; if the value being converted can be
231              represented in fewer digits, it shall be expanded  with  leading
232              zeros.  The default precision shall be 1. The result of convert‐
233              ing zero with an explicit precision of zero  shall  be  no  wide
234              characters.
235
236       u      The  unsigned  argument  shall  be converted to unsigned decimal
237              format in the style "dddd" . The precision specifies the minimum
238              number  of digits to appear; if the value being converted can be
239              represented in fewer digits, it shall be expanded  with  leading
240              zeros.  The default precision shall be 1. The result of convert‐
241              ing zero with an explicit precision of zero  shall  be  no  wide
242              characters.
243
244       x      The unsigned argument shall be converted to unsigned hexadecimal
245              format in the style "dddd" ; the letters "abcdef" are used.  The
246              precision  specifies  the minimum number of digits to appear; if
247              the value being converted can be represented in fewer digits, it
248              shall  be  expanded  with  leading zeros.  The default precision
249              shall be 1. The result of converting zero with an explicit  pre‐
250              cision of zero shall be no wide characters.
251
252       X      Equivalent  to  the  x conversion specifier, except that letters
253              "ABCDEF" are used instead of "abcdef" .
254
255       f, F   The double argument shall be converted to  decimal  notation  in
256              the  style  "[-]ddd.ddd",  where  the number of digits after the
257              radix character shall be equal to the  precision  specification.
258              If the precision is missing, it shall be taken as 6; if the pre‐
259              cision is explicitly zero and no '#' flag is present,  no  radix
260              character  shall  appear. If a radix character appears, at least
261              one digit shall appear before it. The value shall be rounded  in
262              an  implementation-defined  manner  to the appropriate number of
263              digits.
264
265       A double argument representing an infinity shall be converted in one of
266       the  styles  "[-]inf" or "[-]infinity" ; which style is implementation-
267       defined. A double argument representing a NaN shall be converted in one
268       of  the  styles "[-]nan" or "[-]nan(n-char-sequence)"; which style, and
269       the meaning of any n-char-sequence, is  implementation-defined.  The  F
270       conversion  specifier produces "INF" , "INFINITY" , or "NAN" instead of
271       "inf" , "infinity" , or "nan" , respectively.
272
273       e, E   The  double  argument  shall   be   converted   in   the   style
274              "[-]d.ddde±dd",  where there shall be one digit before the radix
275              character (which is non-zero if the argument  is  non-zero)  and
276              the  number  of digits after it shall be equal to the precision;
277              if the precision is missing, it shall be taken as 6; if the pre‐
278              cision  is  zero  and no '#' flag is present, no radix character
279              shall appear. The value shall be rounded in  an  implementation-
280              defined  manner  to the appropriate number of digits. The E con‐
281              version wide character shall produce a number with  'E'  instead
282              of  'e' introducing the exponent. The exponent shall always con‐
283              tain at least two digits.  If the value is  zero,  the  exponent
284              shall be zero.
285
286       A double argument representing an infinity or NaN shall be converted in
287       the style of an f or F conversion specifier.
288
289       g, G   The double argument shall be converted in the style f or  e  (or
290              in  the  style  F or E in the case of a G conversion specifier),
291              with the precision specifying the number of significant  digits.
292              If  an  explicit  precision is zero, it shall be taken as 1. The
293              style used depends on the value converted; style e (or E ) shall
294              be used only if the exponent resulting from such a conversion is
295              less than -4 or greater than or equal to the precision. Trailing
296              zeros  shall  be  removed  from  the  fractional  portion of the
297              result; a radix character shall appear only if it is followed by
298              a digit.
299
300       A double argument representing an infinity or NaN shall be converted in
301       the style of an f or F conversion specifier.
302
303       a, A   A double argument representing a floating-point number shall  be
304              converted  in  the  style "[-]0xh.hhhhp±d", where there shall be
305              one hexadecimal digit (which is non-zero if the  argument  is  a
306              normalized  floating-point  number and is otherwise unspecified)
307              before the decimal-point wide character and the number of  hexa‐
308              decimal  digits after it shall be equal to the precision; if the
309              precision is missing and FLT_RADIX is a power  of  2,  then  the
310              precision shall be sufficient for an exact representation of the
311              value; if the precision is missing and FLT_RADIX is not a  power
312              of 2, then the precision shall be sufficient to distinguish val‐
313              ues of type double, except that trailing zeros may  be  omitted;
314              if  the  precision is zero and the '#' flag is not specified, no
315              decimal-point wide character shall appear. The letters  "abcdef"
316              are used for a conversion and the letters "ABCDEF" for A conver‐
317              sion.  The A conversion specifier produces a number with 'X' and
318              'P'  instead  of 'x' and 'p' . The exponent shall always contain
319              at least one digit, and only as many more digits as necessary to
320              represent  the  decimal exponent of 2. If the value is zero, the
321              exponent shall be zero.
322
323       A double argument representing an infinity or NaN shall be converted in
324       the style of an f or F conversion specifier.
325
326       c      If  no  l  (ell) qualifier is present, the int argument shall be
327              converted to a wide character as if by calling the btowc() func‐
328              tion  and  the resulting wide character shall be written. Other‐
329              wise, the wint_t argument shall be  converted  to  wchar_t,  and
330              written.
331
332       s      If no l (ell) qualifier is present, the application shall ensure
333              that the argument is a pointer to a character array containing a
334              character  sequence beginning in the initial shift state.  Char‐
335              acters from the array shall be converted as if by repeated calls
336              to  the  mbrtowc() function, with the conversion state described
337              by an mbstate_t object initialized  to  zero  before  the  first
338              character  is  converted,  and written up to (but not including)
339              the terminating null wide character. If the precision is  speci‐
340              fied,  no  more than that many wide characters shall be written.
341              If the precision is not specified, or is greater than  the  size
342              of  the  array, the application shall ensure that the array con‐
343              tains a null wide character.
344
345       If an l (ell) qualifier is present, the application shall  ensure  that
346       the  argument is a pointer to an array of type wchar_t. Wide characters
347       from the array shall be written up to (but not including) a terminating
348       null  wide  character. If no precision is specified, or is greater than
349       the size of the array, the application shall ensure that the array con‐
350       tains  a null wide character. If a precision is specified, no more than
351       that many wide characters shall be written.
352
353       p      The application shall ensure that the argument is a  pointer  to
354              void.  The value of the pointer shall be converted to a sequence
355              of printable wide characters in an  implementation-defined  man‐
356              ner.
357
358       n      The  application  shall ensure that the argument is a pointer to
359              an integer into which is written the number of  wide  characters
360              written  to  the  output  so  far  by  this  call  to one of the
361              fwprintf() functions. No argument shall be  converted,  but  one
362              shall  be consumed. If the conversion specification includes any
363              flags, a field width, or a precision, the behavior is undefined.
364
365       C      Equivalent to lc .
366
367       S      Equivalent to ls .
368
369       %      Output a '%' wide character; no  argument  shall  be  converted.
370              The entire conversion specification shall be %% .
371
372
373       If  a  conversion  specification does not match one of the above forms,
374       the behavior is undefined.
375
376       In no case does a nonexistent or small field width cause truncation  of
377       a  field;  if the result of a conversion is wider than the field width,
378       the field shall be expanded to contain the conversion  result.  Charac‐
379       ters  generated  by  fwprintf()  and  wprintf()  shall be printed as if
380       fputwc() had been called.
381
382       For a and A conversions, if FLT_RADIX is not  a  power  of  2  and  the
383       result  is not exactly representable in the given precision, the result
384       should be one of the two adjacent numbers in hexadecimal floating style
385       with  the  given  precision,  with the extra stipulation that the error
386       should have a correct sign for the current rounding direction.
387
388       For e , E , f , F , g , and G conversion specifiers, if the  number  of
389       significant  decimal  digits  is  at  most DECIMAL_DIG, then the result
390       should be correctly rounded. If the number of significant decimal  dig‐
391       its  is  more  than  DECIMAL_DIG but the source value is exactly repre‐
392       sentable with DECIMAL_DIG digits, then the result should  be  an  exact
393       representation  with  trailing  zeros.  Otherwise,  the source value is
394       bounded by two adjacent decimal strings L < U, both having  DECIMAL_DIG
395       significant  digits; the value of the resultant decimal string D should
396       satisfy L <= D <= U, with the extra stipulation that the  error  should
397       have a correct sign for the current rounding direction.
398
399       The st_ctime and st_mtime fields of the file shall be marked for update
400       between the call to a successful execution of fwprintf()  or  wprintf()
401       and the next successful completion of a call to fflush() or fclose() on
402       the same stream, or a call to exit() or abort().
403

RETURN VALUE

405       Upon successful completion, these functions shall return the number  of
406       wide  characters transmitted, excluding the terminating null wide char‐
407       acter in the case of swprintf(), or a negative value if an output error
408       was encountered,    and set errno to indicate the error.
409
410       If  n  or more wide characters were requested to be written, swprintf()
411       shall return a negative value,    and set errno to indicate the error.
412

ERRORS

414       For the conditions under which fwprintf() and wprintf()  fail  and  may
415       fail, refer to fputwc() .
416
417       In addition, all forms of fwprintf() may fail if:
418
419       EILSEQ A  wide-character code that does not correspond to a valid char‐
420              acter has been detected.
421
422       EINVAL There are insufficient arguments.
423
424
425       In addition, wprintf() and fwprintf() may fail if:
426
427       ENOMEM Insufficient storage space is available.
428
429
430       The following sections are informative.
431

EXAMPLES

433       To print the language-independent date and time format,  the  following
434       statement could be used:
435
436
437              wprintf(format, weekday, month, day, hour, min);
438
439       For  American  usage,  format  could be a pointer to the wide-character
440       string:
441
442
443              L"%s, %s %d, %d:%.2d\n"
444
445       producing the message:
446
447
448              Sunday, July 3, 10:02
449
450       whereas for German usage, format could be a pointer to the wide-charac‐
451       ter string:
452
453
454              L"%1$s, %3$d. %2$s, %4$d:%5$.2d\n"
455
456       producing the message:
457
458
459              Sonntag, 3. Juli, 10:02
460

APPLICATION USAGE

462       None.
463

RATIONALE

465       None.
466

FUTURE DIRECTIONS

468       None.
469

SEE ALSO

471       btowc()  ,  fputwc()  ,  fwscanf() , mbrtowc() , setlocale() , the Base
472       Definitions  volume  of  IEEE Std 1003.1-2001,   Chapter   7,   Locale,
473       <stdio.h>, <wchar.h>
474
476       Portions  of  this text are reprinted and reproduced in electronic form
477       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
478       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
479       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
480       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
481       event of any discrepancy between this version and the original IEEE and
482       The  Open Group Standard, the original IEEE and The Open Group Standard
483       is the referee document. The original Standard can be  obtained  online
484       at http://www.opengroup.org/unix/online.html .
485
486
487
488IEEE/The Open Group                  2003                          FWPRINTF(P)
Impressum