Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf - Formatted output of wide characters

&pagelevel(4)&pagelevel

Definition

#include <stdio.h>
#include <wchar.h>

int fwprintf(FILE *fp, const wchar_t *format [, arglist]);

#include <stdarg.h>
#include <wchar.h>

int vwprintf(const wchar_t *format, va_list arg);

#include <wchar.h>

int wprintf(const wchar_t *format [, arglist]);
int swprintf(wchar_t *s, size_t n, const wchar_t *format [, arglist]);

#include <stdarg.h>
#include <stdio.h>
#include <wchar.h>

int vfwprintf(FILE *fp, const wchar_t *format, va_list arg);
int vswprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg);

These functions are used for formatted output.

fwprintf edits the arguments listed in arglist, under control of the wide string pointed to by format, and writes output to the file pointed to by fp.
fwprintf returns when the end of format is reached.

vwprintf corresponds to the function fwprintf with fp = stdout, where the argument list is replaced by an argument of type va_list, which must have been initialized with the macro va_start (possibly followed by va_arg calls). The function does not call the va_end macro.

wprintf correspond to the function fwprintf with fp = stdout.

swprintf writes formatted output to the wide character string s. swprintf is otherwise equivalent to the fwprintf function. A maximum of n wide character codes are written, including the terminating null byte, which is automatically appended when n > 0.

vfwprintf corresponds to the function fwprintf, where the argument list is replaced by an argument of type va_list, which must have been initialized with the macro va_start (possibly followed by va_arg calls). The function does not call the va_end macro.

vswprintf corresponds to the function swprintf, where the argument list is replaced by an argument of type va_list, which must have been initialized with the macro va_start (possibly followed by va_arg calls). The function does not call the va_end macro.


Parameters

format is a wide character string which contains none, one or more conversion directives and wide characters:

  • conversion specifications beginning with the percent character (%), each of which is associated with zero or more arguments in arglist. The results are undefined if fewer arguments are passed in arglist than are defined in format. If the number of arguments defined in format is greater than the arguments passed in arglist, the excess arguments are ignored. The arguments associated with a conversion specification are converted accordingly and written as formatted output to the output data stream.

  • characters of type wchar_t (but not %), which are simply copied to the output stream (1: 1).

  • white-space characters (see section “White space” (Basic terms))

Conversion specifications

Each conversion specification is introduced by the % character, after which the following appear in sequence:

  • Zero or more flags, which modify the meaning of the conversion specification.

  • An optional integer (consisting of decimal digits) or an asterisk (*), which specifies a minimum field width for the output of an argument. If the converted value has fewer bytes than the field width, it will be padded to the field width with spaces on the left (or padded on the right if the left-adjustment flag “-” was specified).

  • An optional precision that specifies the minimum number of digits to appear for the d, i, o, u, x and X conversions; the number of digits to appear after the decimal-point character for the e, E and f conversions; the maximum number of significant digits for the g and G conversions; or the maximum number of characters to be printed from a string in an s conversion. The precision takes the form of a period (.), followed by an integer consisting of decimal digits or an asterisk (*).If only the period is specified, the precision is set to 0.

  • An optional hh, hl, L , j, z or t before a conversion specifier:
    l before c means that the c conversion specifier applies to a wint_t argument;
    l before s means that the s conversion specifier applies to a pointer to a wchar_t argument (i.e. a pointer to a wide character string);
    hh before d, i, o, u, x, or X means that the conversion specifier following h applies to a char or unsignedchar argument (the argument is promoted according to the integral promotions, and its value is converted to char or unsigned char before printing);
    hh before n: means that the following n conversion specifier applies to a pointer to a char argument;
    h before d, i, o, u, x, or X means that the conversion specifier following h applies to a short int or unsigned short int argument (the argument is promoted according to the integral promotions, and its value is converted to short int or unsigned short int before printing);
    h before n means that the following n conversion specifier applies to a pointer to a short int argument;
    l before d, i, o, u, x or X means that the following conversion specifier applies to a long int or unsigned long int argument;
    l before n means that the following n conversion specifier applies to a pointer to a long int;
    ll
    before d, i, o, u, x or X means that the following conversion specifier applies to a long long int or unsigned long long int argument;
    ll before n means that the following conversion specifier applies to an argument of type pointer to long long int; L before e, E, f, g or G: means that the following e, E, f, g or G conversion specifier applies to a long double argument.
    j before d, i, o, u, x or X means that the following conversion specifier applies to a intmax_t or uintmax_t argument;
    j before n means that the following n conversion specifier applies to a pointer to a intmax_t;
    z before d, i, o, u, x or X means that the following conversion specifier applies to a size_t argument;
    z before n means that the following n conversion specifier applies to a pointer to a size_t;
    t before d, i, o, u, x or X means that the following conversion specifier applies to a ptrdiff_t argument;
    t before n means that the following n conversion specifier applies to a pointer to a ptrdiff_t;
    L before a, Ae, E, f, Fg or G means that the following conversion specifier applies to a long double argument
    If an hh, h, l, ll, L, j, z or t appears with any other conversion specifier, the behavior is undefined.

  • A conversion character of type wchar_t that indicates the type of conversion to be applied, see the listing below.

A field width, or precision, or both, may be indicated by an asterisk (*). In this case an argument of type int supplies the field width or precision. Arguments specifying field width, or precision, or both must appear in that order before the argument, if any, to be converted. A negative field width is taken as a “-” flag followed by a positive field width. A negative precision is taken as if the precision were omitted.

Conversion specifications have the following structure:

%

[-][+]['BLANK'][#][0]

[n|*]

[.m|.*]

{[hh|h|l|ll|j|z|t]{d|i|o|u|x|X} |
 [hh|h|l|ll|j|z|t]n |
 [L]{a|A|e|E|f|F|g|G} |
 [l]{c|s} |
 {D|O|U|C|S|p} |
 %}

1.

  2.

   3.

    4.

    5.

  1. Start of a conversion specification
  2. Flags

  3. Field width

  4. Precision

  5. Characters that define the actual conversion

Flags

-

The result of the conversion will be left-justified within the array.

+

The result of a signed conversion will always begin with a sign (+ or -).

'BLANK'

If the first wide character of a signed conversion is not a sign or the result of a signed conversion is not a wide character, a space will be prefixed to the result. This means that if the space and + flags both appear, the space flag will be ignored.

#

This flag specifies that the value is to be converted to an alternative form.
This flag has no effect for c, d, i, s and u.

For o conversion, it increases the precision to force the first digit of the result to be 0.
For x or X conversions, a non-zero result will have the string "0x" (or "0X") prefixed to it.
For e, E, f, g or G conversions, the result will always contain a wide radix character, even if no digits follow the radix character. Without this flag, a radix character appears in the result of these conversions only if a digit follows it.
For g and G conversions, trailing zeros will not be removed from the result as they normally are. For other conversions, the behavior is undefined.

0

For d, i, o, u, x, X, e, E, f, g and G conversions, leading zeros (following any indication of sign or base) are used to pad to the array width; no space padding is performed. If the 0 and - flags both appear, the 0 flag will be ignored.
For d, i, o, u, x and X conversions, if a precision is specified, the 0 flag will be ignored. For other conversions, the behavior is undefined.

n     

Minimum field width (including radix character). If more positions are required for the conversion of a number, this specification has no effect. If the output is shorter than the specified field width, it is padded with blanks or zeros up to the field width (see flags - and 0).

*

The total field width (see n) is defined by an argument instead of a conversion specification. The current (integral) value must immediately precede the argument to be converted or the value of the precision specification (flag .m) in the argument list (delimited by a comma).

.m

Precision specification.

d, i, o, u, x resp. X conversions: minimal number of digits to be output. Defaulit: 1.
e-, E-, f, F conversions: exact number of positions after the radix character. Default: 6 positions.
a, A conversions: exact number of positions after the radix character. Default: 13 positions for long, 27 positions for long double.
g resp. G conversions: maximum number of significant positions. 
s conversion: maximum number of characters to be output. Default: all characters up to the terminating null byte.
The precision specification is ignored for all other conversions.

.*

The precision (see .m) is defined by an argument instead of a conversion specification. The current (integral) value must immediately precede the argument to be converted in the argument list (delimited by a comma).

Conversion characters

d, i

The int argument is converted to a signed decimal in the style [-]dddd. The precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it will be expanded with leading zeros. The default precision is 1.
The result of converting 0 with an explicit precision of 0 is no characters.

o, u

The unsigned int argument is converted to unsigned octal format (o) or in an unsigned decimal number (u) in the style dddd. The precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it will be expanded with leading zeros. The default precision is 1.
The result of converting 0 with an explicit precision of 0 is no characters.

x, X

The unsigned int argument is converted to unsigned hexadecimal format in the style dddd; the letters abcdef (for x) or ABCDEF (for X) are used in addition to the digits. The precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it will be expanded with leading zeros. The default precision is 1. The result of converting 0 with an explicit precision of 0 is no characters.

f, F

The double argument is converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the radix character is equal to the precision specification.
If the precision is missing, it is taken as 6.
If the precision is explicitly 0 and no # flag is present, no radix character appears.
If a radix character appears, at least one digit appears before it. The value is rounded to the appropriate number of digits.

e, E

The double argument is converted in the style [-]d.ddde+-dd, where there is one digit before the radix character (which is non-zero if the argument is non-zero) and the number of digits after it is equal to the precision; if the precision is missing, it is taken as 6.
If the precision is 0 and no # flag is present, no radix character appears. The value is rounded to the appropriate number of digits.
The E conversion character will produce a number with E instead of e introducing the exponent. The exponent always contains at least two digits. If the value is 0, the exponent is 0.

g, G

The double argument is converted in the style f or e (or in the style E in the case of a G conversion character), with the precision specifying the number of significant digits. If an explicit precision is 0, it is taken as 1.
The style used depends on the value converted; style e (or E) will be used only if the exponent resulting from such a conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional portion of the result; a radix character appears only if it is followed by a digit.

a, A

The double argument (float oder double) is converted in the style[-]0xh.hhhh p{+|-} d. Each h represents a hexadecimal digit.  The radix character is determined by the locale (category LC_NUMERIC). The default is a period. The exponent is printed to base 2. The a conversion character will produce a number with lowercase letters a, b, c, d, e , f, x and p, the A conversion character a number with uppercase letters A, B, C, DE, F, X and P.  The number of positions after the radix character depends on the precision specified in .m; the default is 27 positions if used together with the conversion character L, 13 otherwise. If the precision is set to 0, the output will include the output will have no radix character.

c   

If the character l precedes it, the argument is converted from type wint_t to type wchar_t, the resulting character is written.
If not preceded by l, the argument is converted from type int to a wide character, just like for the btowc() function call. The resulting character is written.

s

If not preceded by a l, the argument is of type pointer to a char array. Characters in the array are converted in the same manner as when the mbrtowc() function is called. The conversion status is written to an object of type mbstate_t and initialized to 0 before the first multi-byte character is converted. Data is written up to the terminating null character (and only to there).

If preceded by a l, the argument is of type pointer to a wchar_t array. Wide characters from the array are written up to the terminating null character (and only to there).

If a precision m is specified, no more than m bytes are written. If the precision is not specified or is greater than the size of the array, the array must contain a wide character null byte (as a terminator).

S

Same as ls.

C

Same as lc.

p

The argument must be a pointer to void. The value is output as an 8-digit hexadecimal number.

n

The argument must be a pointer to int into which is written the number of bytes written to the output so far by this call to one of the fwprintf functions. No argument is converted.

%

The wide character % is output; no argument is converted. The complete conversion specification must be of the form %%.

If the character that follows % is not a valid conversion character, the result of the conversion is undefined.

If an argument is a UNION or a pointer to a UNION, the result of the conversion is undefined. The same applies when an argument is an array or a pointer to an array, except for the following three cases:

  • The argument is an array of type char and uses %s,
  • the argument is an array of type wchar_t and uses %ls or
  • the argument is a pointer and uses %p.

A non-existent array width or a missing array width will never result in the truncation of an array. If the result of a conversion is wider than the array width, the array is simply extended to accept the output.

If the character that follows % is not a valid conversion character, the result of the conversion is undefined.

In no case does a non-existent or a too small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is simply expanded to accomodate the conversion result.

Returnwert

Number of wide characters printed


                        if successful


Negative value if an error occurs.

Hinweise

This version of the C runtime system only supports one-byte characters as wide character codes.

The following applies in the case of text files with SAM access mode and variable record length for which a maximum record length is also specified: When the specification split=no was entered for fopen, records which are longer than the maximum record length are truncated to the maximum record length when they are written. By default or with the specification split=yes, these records are split into multiple records. If a record has precisely the maximum record length, a record of the length zero is written after it.

See also

btowc, fprintf, mbrtowc, printf