fwprintf(3S)
fwprintf: fwprintf, wprintf, swprintf - print formatted wide-character output
As shipped in IRIX 6.5.19. Added in IRIX 6.5.19.
NAME fwprintf: fwprintf, wprintf, swprintf - print formatted wide-character output SYNOPSIS #include <stdio.h> #include <wchar.h> int fwprintf(FILE *stream, const wchar_t *format, ...); int wprintf(const wchar_t *format, ...); int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...); DESCRIPTION fwprintf places output on the named output stream. wprintf places output on stdout. swprintf places output, followed by a null wide-character in consecutive wide-characters starting at *s; no more than n wide-characters are written, including a terminating null wide-character, which is always added (unless n is zero). Each function returns the number of wide-characters transmitted (not including the terminating null character in the case of swprintf), or a negative value if an output error was encountered. If n or more wide- characters were requested to be written swprintf returns a negative value. Each of these functions converts, formats, and prints its args under control of the format wide-character string. The results are undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments are simply ignored. The format is a wide-character string that contains two types of objects defined below: 1. ordinary wide-characters, which are simply copied to the output stream; 2. conversion specifications. All forms of the fwprintf functions allow for the insertion of a language-dependent decimal-point character. The decimal-point character is defined by the program's locale (category LC_NUMERIC). In the "C" locale, or in a locale where the decimal-point character is not defined, the decimal-point character defaults to a period (.). Each conversion specification is introduced by the character %, and takes the following general form and sequence: %[posp$][flags][width][.precision][size]fmt posp$ An optional entry, consisting of one or more decimal digits followed by a $ character, specifying the number of the next arg to access. The first arg (just after format) is numbered 1. If this field is not specified, the arg following the most recently used arg will be used. flags Zero or more characters that modify the meaning of the conversion specification. The flag characters and their meanings are: ' The integer portion of the result of a decimal conversion (for i, d, u, f, g, or G conversions) will be formatted with the thousands' grouping characters. The non-monetary grouping character will be used. - The result of the conversion will be left-justified within the field. (It will be right-justified if this flag is not specified.) + The result of a signed conversion will always begin with a sign (+ or -). (It will begin with a sign only when a negative value is converted if this flag is not specified.) space If the first wide-character of a signed conversion is not a sign, or if a signed conversion results in no characters, a space will be prefixed to the result. If the space and + flags both appear, the space flag will be ignored. # The value is to be converted to an alternate form. For an o conversion, it increases the precision (if necessary) to force the first digit of the result to be a zero. For x (or X) conversion, a nonzero result will have 0x (or 0X) prefixed to it. For e, E, f, g, and G conversions, the result will always contain a decimal-point character, even if no digits follow it. (Normally, a decimal point 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 c, d, i, s, and u conversions, the flag has no effect. 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 field 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. If the 0 and ' flags both appear, the grouping wide-characters are inserted before zero padding. For other conversions, the behavior is undefined. width An optional entry that consists of either one or more decimal digits, or an asterisk (*), or an asterisk followed by one or more decimal digits and a $. It specifies the minimum field width: If the converted value has fewer wide-characters than the field width, it will be padded (with space by default) on the left or right (see the above flags description) to the field width. .prec An optional entry that consists of a period (.) followed by either zero or more decimal digits, or an asterisk (*), or an asterisk followed by one or more decimal digits and a $. It 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 wide-characters to be written from a string for an s conversion. For other conversions, the behavior is undefined. If only a period is specified, the precision is taken as zero. size An optional l (ell) specifies that a following c conversion wide- character applies to a wint_t argument; an optional l (ell) specifies that a following s conversion wide-character applies to a wchar_t argument; an optional h specifies that a following d, i, o, u,x or X conversion wide-character applies to a type short int or type unsigned short int argument (the argument will have been promoted according to the integral promotions, and its value will be converted to type short int or unsigned short int before printing); an optional h specifies that a following n conversion wide-character applies to a pointer to a type short int argument; an optional l (ell) specifies that a following d, i, o, u, x or X conversion wide-character applies to a type long int or unsigned long int argument; an optional l (ell) specifies that a following n conversion wide-character applies to a pointer to a type long int argument; or an optional L specifies that a following e, E, f, g or G conversion wide-character applies to a type long double argument. If an h, l or L appears with any other conversion wide-character, the behaviour is undefined. If a size appears other than in the following combinations, the behavior is undefined. fmt A conversion wide-character (described below) that indicates the type of conversion to be applied. When a width or .prec includes an asterisk (*), an int arg supplies the width or precision. When they do not include a $, the arguments specifying a field width, or precision, or both must appear (in that order) before the argument (if any) to be converted. If the conversion specification includes posp$, the field width and precision may include a $. The decimal digits that precede the $ similarly specify the number of the arg that contains the field width or precision. (In this case, posp$ specifies the number of the arg to convert.) A negative field width argument is taken as a - flag followed by a positive field width. If the precision argument is negative, it will be taken as zero. When numbered argument specifications are used, specifying the Nth argument requires that all the leading arguments, from the first to the (N-1)th, be specified at least once, in a consistent manner in the format string. The conversion characters and their meanings are: d, i The integer arg is converted to signed decimal. 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 a zero value with a precision of zero is no characters. o, u, x, X The unsigned integer arg is converted to unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal notation (x and X). The x conversion uses the letters abcdef and the X conversion uses the letters ABCDEF. 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 a zero value with a precision of zero is no characters. f The floating arg is converted to decimal notation in the style [-]ddd.ddd, where the number of digits after the decimal-point character [see setlocale(3C)] is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is zero and the # flag is not specified, no decimal- point character appears. If a decimal-point character appears, at least one digit appears before it. The value is rounded to the appropriate number of digits. The fwprintf() family of functions may make available wide-character string representations for infinity and NaN. e, E The double arg is converted to the style [-]d.ddde_dd, where there is one digit before the decimal-point character (which is nonzero if the argument is nonzero) 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 zero and the # flag is not specified, no decimal- point character appears. The value is rounded to the appropriate number of digits. The E conversion wide-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 zero, the exponent is zero. 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 wide-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. The fwprintf family of functions may make available wide-character string representations for infinity and NaN. c If no l (ell) qualifier is present, the int argument is converted to a wide-character as if by calling the btowc() function and the resulting wide-character is written. Otherwise the wint_t argument is converted to wchar_t and written. C arg is interpreted as a wchar_t, converted to a multi-byte sequence, and the resulting byte(s) are written. s If no l (ell) qualifier is present, the argument must be a pointer to a character array containing a character sequence beginning in the initial shift state. Characters from the array are converted as if by repeated calls to the mbrtowc() function, with the conversion state described by an mbstate_t object initialised to zero before the first character is converted, and written up to (but not including) the terminating null wide-character. If the precision is specified, no more than that many wide-characters are written. If the precision is not specified or is greater than the size of the array, the array must contain a null wide-character. If an l (ell) qualifier is present, the argument must be a pointer to an array of type wchar_t. Wide characters from the array are written up to (but not including) a terminating null wide-character. If no precision is specified or is greater than the size of the array, the array must contain a null wide-character. If a precision is specified, no more than that many wide-characters are written. (A null pointer for arg will yield undefined results.) S The arg is taken to be a pointer to an array of wide characters (wchar_t). Each character from the array is converted to a multi- byte sequence and the resulting byte(s) are written. Conversion stops when there is a null wide character in the array. If a precision is specified, no more than that many characters are written. If a precision is not specified or is greater than the size of the array, the array must contain a terminating null character. (A null pointer for arg will yield undefined results.) p The arg is taken to be a pointer to void. The value of the pointer is converted to an implementation-defined sequence of printable characters, which matches those read by the %p conversion of the wscanf function. n The arg is taken to be a pointer to an integer into which is written the number of characters written so far by this call to fwprintf, wprintf, or swprintf. No argument is converted. % Print a %; no argument is converted. The complete specification must be simply %%. If the form of the conversion specification does not match any of the above, the results of the conversion are undefined. Similarly, the results are undefined if there are insufficient args for the format. If the format is exhausted while args remain, the excess args are ignored. If a floating-point value is the internal representation for infinity, the output is [_]inf, where inf is either inf or INF, depending on whether the conversion character is lowercase or uppercase. Printing of the sign follows the rules described above. If a floating-point value is the internal representation for ``not-a- number,'' the output is [_]nan0xm. Depending on the conversion character, nan is either nan or NAN. Additionally, 0xm represents the most significant part of the mantissa. Again depending on the conversion character, x will be x or X, and m will use the letters abcdef or ABCDEF. Printing of the sign follows the rules described above. In no case does a nonexistent or small field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is expanded to contain the conversion result. Characters generated by wprintf and fwprintf are printed as if the wputc routine had been called repeatedly. EXAMPLES To print a date and time in the form ``Sunday, July 3, 10:02,'' where weekday and month are pointers to null-terminated strings: wprintf(L"%s, %s %d, %d:%.2d", weekday, month, day, hour, min); To print the language-independent date and time format, the following statement could be used: wprintf (format, weekday, month, day, hour, min); For American usage, format could be a pointer to the wide-character string: L"%s, %s %d, %d:%.2d" producing the message: Sunday, July 3, 10:02 whereas for German usage, format could be a pointer to the wide-character string: L"%1$s, %3$d. %2$s, %4$d:%5$.2d" producing the message: Sonntag, 3. Juli, 10:02 NOTES These functions are supported in n32 and 64 bit C Libraries for IRIX 6.5.17 and later versions. SEE ALSO btowc(3S), fputwc(3S), fwscanf(3S), setlocale(3C), mbrtowc(3C), stdio(3S). DIAGNOSTICS fwprintf, wprintf, and swprintf return the number of wide-characters transmitted (not counting the terminating null character for swprintf), or return a negative value if an error was encountered. If n or more wide characters were requested to be written swprintf returns a negative value. In addition, all forms of fwprintf() may fail if: [EILSEQ] A wide-character code that does not correspond to a valid character has been detected. [EINVAL] There are insufficient arguments. In addition, wprintf() and fwprintf() may fail if: [ENOMEM] Insufficient storage space is available.