890 lines
43 KiB
HTML
890 lines
43 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>fprintf</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="fprintf"></a> <a name="tag_03_180"></a><!-- fprintf -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_180_01"></a>NAME</h4>
|
|
|
|
<blockquote>fprintf, printf, snprintf, sprintf - print formatted output</blockquote>
|
|
|
|
<h4><a name="tag_03_180_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/stdio.h.html">stdio.h</a>><br>
|
|
<br>
|
|
int fprintf(FILE *restrict</tt> <i>stream</i><tt>, const char *restrict</tt> <i>format</i><tt>, ...);<br>
|
|
int printf(const char *restrict</tt> <i>format</i><tt>, ...);<br>
|
|
int snprintf(char *restrict</tt> <i>s</i><tt>, size_t</tt> <i>n</i><tt>,<br>
|
|
const char *restrict</tt> <i>format</i><tt>, ...);<br>
|
|
int sprintf(char *restrict</tt> <i>s</i><tt>, const char *restrict</tt> <i>format</i><tt>, ...);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
|
|
border="0"> The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the
|
|
requirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to
|
|
the ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div>
|
|
|
|
<p>The <i>fprintf</i>() function shall place output on the named output <i>stream</i>. The <i>printf</i>() function shall place
|
|
output on the standard output stream <i>stdout</i>. The <i>sprintf</i>() function shall place output followed by the null byte,
|
|
<tt>'\0'</tt> , in consecutive bytes starting at *<i>s</i>; it is the user's responsibility to ensure that enough space is
|
|
available.</p>
|
|
|
|
<p>The <i>snprintf</i>() function shall be equivalent to <i>sprintf</i>(), with the addition of the <i>n</i> argument which states
|
|
the size of the buffer referred to by <i>s</i>. If <i>n</i> is zero, nothing shall be written and <i>s</i> may be a null pointer.
|
|
Otherwise, output bytes beyond the <i>n</i>-1st shall be discarded instead of being written to the array, and a null byte is
|
|
written at the end of the bytes actually written into the array.</p>
|
|
|
|
<p>If copying takes place between objects that overlap as a result of a call to <i>sprintf</i>() or <i>snprintf</i>(), the results
|
|
are undefined.</p>
|
|
|
|
<p>Each of these functions converts, formats, and prints its arguments under control of the <i>format</i>. The <i>format</i> is a
|
|
character string, beginning and ending in its initial shift state, if any. The <i>format</i> is composed of zero or more
|
|
directives: <i>ordinary characters</i>, which are simply copied to the output stream, and <i>conversion specifications</i>, each of
|
|
which shall result in the fetching of zero or more arguments. The results are undefined if there are insufficient arguments for the
|
|
<i>format</i>. If the <i>format</i> is exhausted while arguments remain, the excess arguments shall be evaluated but are otherwise
|
|
ignored.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Conversions can be applied to the <i>n</i>th argument after the <i>format</i> in the argument list, rather than to the next unused
|
|
argument. In this case, the conversion specifier character <tt>%</tt> (see below) is replaced by the sequence
|
|
<tt>"%</tt><i>n</i><tt>$"</tt>, where <i>n</i> 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).</p>
|
|
|
|
<p>The <i>format</i> can contain either numbered argument conversion specifications (that is, <tt>"%</tt><i>n</i><tt>$"</tt> and
|
|
<tt>"*</tt><i>m</i><tt>$"</tt>), or unnumbered argument conversion specifications (that is, <tt>%</tt> and <tt>*</tt> ), but not
|
|
both. The only exception to this is that <tt>%%</tt> can be mixed with the <tt>"%</tt><i>n</i><tt>$"</tt> form. The results of
|
|
mixing numbered and unnumbered argument specifications in a <i>format</i> string are undefined. When numbered argument
|
|
specifications are used, specifying the <i>N</i>th argument requires that all the leading arguments, from the first to the
|
|
(<i>N-1</i>)th, are specified in the format string.</p>
|
|
|
|
<p>In format strings containing the <tt>"%</tt><i>n</i><tt>$"</tt> form of conversion specification, numbered arguments in the
|
|
argument list can be referenced from the format string as many times as required. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></p>
|
|
|
|
<p>In format strings containing the <tt>%</tt> form of conversion specification, each conversion specification uses the first
|
|
unused argument in the argument list.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> All
|
|
forms of the <i>fprintf</i>() functions allow for the insertion of a language-dependent radix character in the output string. The
|
|
radix character is defined in the program's locale (category <i>LC_NUMERIC ).</i> In the POSIX locale, or in a locale where the
|
|
radix character is not defined, the radix character shall default to a period ( <tt>'.'</tt> ). <img src="../images/opt-end.gif"
|
|
alt="[Option End]" border="0"></p>
|
|
|
|
<p>Each conversion specification is introduced by the <tt>'%'</tt> character <sup>[<a href=
|
|
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or by the
|
|
character sequence <tt>"%</tt><i>n</i><tt>$"</tt>, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> after which the
|
|
following appear in sequence:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>Zero or more <i>flags</i> (in any order), which modify the meaning of the conversion specification.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>An optional minimum <i>field width</i>. If the converted value has fewer bytes than the field width, it shall be padded with
|
|
spaces by default on the left; it shall be padded on the right if the left-adjustment flag ( <tt>'-'</tt> ), described below, is
|
|
given to the field width. The field width takes the form of an asterisk ( <tt>'*'</tt> ), described below, or a decimal
|
|
integer.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>An optional <i>precision</i> that gives the minimum number of digits to appear for the <tt>d</tt> , <tt>i</tt> , <tt>o</tt> ,
|
|
<tt>u</tt> , <tt>x</tt> , and <tt>X</tt> conversion specifiers; the number of digits to appear after the radix character for the
|
|
<tt>a</tt> , <tt>A</tt> , <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , and <tt>F</tt> conversion specifiers; the maximum number of
|
|
significant digits for the <tt>g</tt> and <tt>G</tt> conversion specifiers; or the maximum number of bytes to be printed from a
|
|
string in the <tt>s</tt> <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> and <tt>S</tt> <img src="../images/opt-end.gif" alt="[Option End]" border="0"> conversion
|
|
specifiers. The precision takes the form of a period ( <tt>'.'</tt> ) followed either by an asterisk ( <tt>'*'</tt> ), described
|
|
below, or an optional decimal digit string, where a null digit string is treated as zero. If a precision appears with any other
|
|
conversion specifier, the behavior is undefined.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>An optional length modifier that specifies the size of the argument.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A <i>conversion specifier</i> character that indicates the type of conversion to be applied.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>A field width, or precision, or both, may be indicated by an asterisk ( <tt>'*'</tt> ). In this case an argument of type
|
|
<b>int</b> supplies the field width or precision. Applications shall ensure that arguments specifying field width, or precision, or
|
|
both appear in that order before the argument, if any, to be converted. A negative field width is taken as a <tt>'-'</tt> flag
|
|
followed by a positive field width. A negative precision is taken as if the precision were omitted. <sup>[<a href=
|
|
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> In format
|
|
strings containing the <tt>"%</tt><i>n</i><tt>$"</tt> form of a conversion specification, a field width or precision may be
|
|
indicated by the sequence <tt>"*</tt><i>m</i><tt>$"</tt>, where <i>m</i> is a decimal integer in the range [1,{NL_ARGMAX}] giving
|
|
the position in the argument list (after the <i>format</i> argument) of an integer argument containing the field width or
|
|
precision, for example:</p>
|
|
|
|
<pre>
|
|
<tt>printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);<img src="../images/opt-end.gif" border="0">
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The flag characters and their meanings are:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>'</tt></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The integer portion of the result of a decimal conversion ( <tt>%i</tt> , <tt>%d</tt> , <tt>%u</tt> , <tt>%f</tt> , <tt>%F</tt> ,
|
|
<tt>%g</tt> , or <tt>%G</tt> ) shall be formatted with thousands' grouping characters. For other conversions the behavior is
|
|
undefined. The non-monetary grouping character is used. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt><tt>-</tt></dt>
|
|
|
|
<dd>The result of the conversion shall be left-justified within the field. The conversion is right-justified if this flag is not
|
|
specified.</dd>
|
|
|
|
<dt><tt>+</tt></dt>
|
|
|
|
<dd>The result of a signed conversion shall always begin with a sign ( <tt>'+'</tt> or <tt>'-'</tt> ). The conversion shall begin
|
|
with a sign only when a negative value is converted if this flag is not specified.</dd>
|
|
|
|
<dt><space></dt>
|
|
|
|
<dd>If the first character of a signed conversion is not a sign or if a signed conversion results in no characters, a <space>
|
|
shall be prefixed to the result. This means that if the <space> and <tt>'+'</tt> flags both appear, the <space> flag
|
|
shall be ignored.</dd>
|
|
|
|
<dt><tt>#</tt></dt>
|
|
|
|
<dd>Specifies that the value is to be converted to an alternative form. For <tt>o</tt> conversion, it increases the precision (if
|
|
necessary) to force the first digit of the result to be zero. For <tt>x</tt> or <tt>X</tt> conversion specifiers, a non-zero result
|
|
shall have 0x (or 0X) prefixed to it. For <tt>a</tt> , <tt>A</tt> , <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , <tt>F</tt> , <tt>g</tt>
|
|
, and <tt>G</tt> conversion specifiers, the result shall always contain a 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
|
|
<tt>g</tt> and <tt>G</tt> conversion specifiers, trailing zeros shall <i>not</i> be removed from the result as they normally are.
|
|
For other conversion specifiers, the behavior is undefined.</dd>
|
|
|
|
<dt><tt>0</tt></dt>
|
|
|
|
<dd>For <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , <tt>X</tt> , <tt>a</tt> , <tt>A</tt> , <tt>e</tt> ,
|
|
<tt>E</tt> , <tt>f</tt> , <tt>F</tt> , <tt>g</tt> , and <tt>G</tt> conversion specifiers, leading zeros (following any indication
|
|
of sign or base) are used to pad to the field width; no space padding is performed. If the <tt>'0'</tt> and <tt>'-'</tt> flags both
|
|
appear, the <tt>'0'</tt> flag is ignored. For <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , and <tt>X</tt>
|
|
conversion specifiers, if a precision is specified, the <tt>'0'</tt> flag is ignored. <sup>[<a href=
|
|
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> If the
|
|
<tt>'0'</tt> and <tt>'"</tt> flags both appear, the grouping characters are inserted before zero padding. For other conversions,
|
|
the behavior is undefined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
|
|
<p>The length modifiers and their meanings are:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>hh</tt></dt>
|
|
|
|
<dd>Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to a <b>signed char</b> or <b>unsigned char</b> argument (the argument will have been promoted according to the integer
|
|
promotions, but its value shall be converted to <b>signed char</b> or <b>unsigned char</b> before printing); or that a following
|
|
<tt>n</tt> conversion specifier applies to a pointer to a <b>signed char</b> argument.</dd>
|
|
|
|
<dt><tt>h</tt></dt>
|
|
|
|
<dd>Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to a <b>short</b> or <b>unsigned short</b> argument (the argument will have been promoted according to the integer
|
|
promotions, but its value shall be converted to <b>short</b> or <b>unsigned short</b> before printing); or that a following
|
|
<tt>n</tt> conversion specifier applies to a pointer to a <b>short</b> argument.</dd>
|
|
|
|
<dt><tt>l</tt> (ell)</dt>
|
|
|
|
<dd>Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to a <b>long</b> or <b>unsigned long</b> argument; that a following <tt>n</tt> conversion specifier applies to a pointer to
|
|
a <b>long</b> argument; that a following <tt>c</tt> conversion specifier applies to a <b>wint_t</b> argument; that a following
|
|
<tt>s</tt> conversion specifier applies to a pointer to a <b>wchar_t</b> argument; or has no effect on a following <tt>a</tt> ,
|
|
<tt>A</tt> , <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , <tt>F</tt> , <tt>g</tt> , or <tt>G</tt> conversion specifier.</dd>
|
|
|
|
<dt><tt>ll</tt> (ell-ell)</dt>
|
|
|
|
<dd><br>
|
|
Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to a <b>long long</b> or <b>unsigned long long</b> argument; or that a following <tt>n</tt> conversion specifier applies to
|
|
a pointer to a <b>long long</b> argument.</dd>
|
|
|
|
<dt><tt>j</tt></dt>
|
|
|
|
<dd>Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to an <b>intmax_t</b> or <b>uintmax_t</b> argument; or that a following <tt>n</tt> conversion specifier applies to a
|
|
pointer to an <b>intmax_t</b> argument.</dd>
|
|
|
|
<dt><tt>z</tt></dt>
|
|
|
|
<dd>Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to a <b>size_t</b> or the corresponding signed integer type argument; or that a following <tt>n</tt> conversion specifier
|
|
applies to a pointer to a signed integer type corresponding to a <b>size_t</b> argument.</dd>
|
|
|
|
<dt><tt>t</tt></dt>
|
|
|
|
<dd>Specifies that a following <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , or <tt>X</tt> conversion specifier
|
|
applies to a <b>ptrdiff_t</b> or the corresponding <b>unsigned</b> type argument; or that a following <tt>n</tt> conversion
|
|
specifier applies to a pointer to a <b>ptrdiff_t</b> argument.</dd>
|
|
|
|
<dt><tt>L</tt></dt>
|
|
|
|
<dd>Specifies that a following <tt>a</tt> , <tt>A</tt> , <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , <tt>F</tt> , <tt>g</tt> , or
|
|
<tt>G</tt> conversion specifier applies to a <b>long double</b> argument.</dd>
|
|
</dl>
|
|
|
|
<p>If a length modifier appears with any conversion specifier other than as specified above, the behavior is undefined.</p>
|
|
|
|
<p>The conversion specifiers and their meanings are:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>d</tt>, <tt>i</tt></dt>
|
|
|
|
<dd>The <b>int</b> argument shall be converted to a signed decimal in the style <tt>"[-]</tt><i>dddd</i><tt>"</tt>. The precision
|
|
specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it shall be
|
|
expanded with leading zeros. The default precision is 1. The result of converting zero with an explicit precision of zero shall be
|
|
no characters.</dd>
|
|
|
|
<dt><tt>o</tt></dt>
|
|
|
|
<dd>The <b>unsigned</b> argument shall be converted to unsigned octal format in the style <tt>"</tt><i>dddd</i><tt>"</tt>. The
|
|
precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it
|
|
shall be expanded with leading zeros. The default precision is 1. The result of converting zero with an explicit precision of zero
|
|
shall be no characters.</dd>
|
|
|
|
<dt><tt>u</tt></dt>
|
|
|
|
<dd>The <b>unsigned</b> argument shall be converted to unsigned decimal format in the style <tt>"</tt><i>dddd</i><tt>"</tt>. The
|
|
precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it
|
|
shall be expanded with leading zeros. The default precision is 1. The result of converting zero with an explicit precision of zero
|
|
shall be no characters.</dd>
|
|
|
|
<dt><tt>x</tt></dt>
|
|
|
|
<dd>The <b>unsigned</b> argument shall be converted to unsigned hexadecimal format in the style <tt>"</tt><i>dddd</i><tt>"</tt>;
|
|
the letters <tt>"abcdef"</tt> are used. The precision specifies the minimum number of digits to appear; if the value being
|
|
converted can be represented in fewer digits, it shall be expanded with leading zeros. The default precision is 1. The result of
|
|
converting zero with an explicit precision of zero shall be no characters.</dd>
|
|
|
|
<dt><tt>X</tt></dt>
|
|
|
|
<dd>Equivalent to the <tt>x</tt> conversion specifier, except that letters <tt>"ABCDEF"</tt> are used instead of <tt>"abcdef"</tt>
|
|
.</dd>
|
|
|
|
<dt><tt>f</tt>, <tt>F</tt></dt>
|
|
|
|
<dd>The <b>double</b> argument shall be converted to decimal notation in the style
|
|
<tt>"[-]</tt><i>ddd</i><tt>.</tt><i>ddd</i><tt>"</tt>, where the number of digits after the radix character is equal to the
|
|
precision specification. If the precision is missing, it shall be taken as 6; if the precision is explicitly zero and no
|
|
<tt>'#'</tt> flag is present, no radix character shall appear. If a radix character appears, at least one digit appears before it.
|
|
The low-order digit shall be rounded in an implementation-defined manner.
|
|
|
|
<p>A <b>double</b> argument representing an infinity shall be converted in one of the styles <tt>"[-]inf"</tt> or
|
|
<tt>"[-]infinity"</tt> ; which style is implementation-defined. A <b>double</b> argument representing a NaN shall be converted in
|
|
one of the styles <tt>"[-]nan(</tt><i>n-char-sequence</i><tt>)"</tt> or <tt>"[-]nan"</tt> ; which style, and the meaning of any
|
|
<i>n-char-sequence</i>, is implementation-defined. The <tt>F</tt> conversion specifier produces <tt>"INF"</tt> ,
|
|
<tt>"INFINITY"</tt> , or <tt>"NAN"</tt> instead of <tt>"inf"</tt> , <tt>"infinity"</tt> , or <tt>"nan"</tt> , respectively.</p>
|
|
</dd>
|
|
|
|
<dt><tt>e</tt>, <tt>E</tt></dt>
|
|
|
|
<dd>The <b>double</b> argument shall be converted in the style
|
|
<tt>"[-]</tt><i>d</i><tt>.</tt><i>ddd</i><tt>e±</tt><i>dd</i><tt>"</tt>, 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 shall be taken as 6; if the precision is zero and no <tt>'#'</tt> flag is present, no radix character shall appear. The
|
|
low-order digit shall be rounded in an implementation-defined manner. The <tt>E</tt> conversion specifier shall produce a number
|
|
with <tt>'E'</tt> instead of <tt>'e'</tt> introducing the exponent. The exponent shall always contain at least two digits. If the
|
|
value is zero, the exponent shall be zero.
|
|
|
|
<p>A <b>double</b> argument representing an infinity or NaN shall be converted in the style of an <tt>f</tt> or <tt>F</tt>
|
|
conversion specifier.</p>
|
|
</dd>
|
|
|
|
<dt><tt>g</tt>, <tt>G</tt></dt>
|
|
|
|
<dd>The <b>double</b> argument shall be converted in the style <tt>f</tt> or <tt>e</tt> (or in the style <tt>F</tt> or <tt>E</tt>
|
|
in the case of a <tt>G</tt> conversion specifier), with the precision specifying the number of significant digits. If an explicit
|
|
precision is zero, it shall be taken as 1. The style used depends on the value converted; style <tt>e</tt> (or <tt>E</tt> ) shall
|
|
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 shall be removed from the fractional portion of the result; a radix character shall appear only if it is followed by a digit
|
|
or a <tt>'#'</tt> flag is present.
|
|
|
|
<p>A <b>double</b> argument representing an infinity or NaN shall be converted in the style of an <tt>f</tt> or <tt>F</tt>
|
|
conversion specifier.</p>
|
|
</dd>
|
|
|
|
<dt><tt>a</tt>, <tt>A</tt></dt>
|
|
|
|
<dd>A <b>double</b> argument representing a floating-point number shall be converted in the style
|
|
<tt>"[-]0x</tt><i>h</i><tt>.</tt><i>hhhh</i><tt>p±</tt><i>d</i><tt>"</tt>, where there is one hexadecimal digit (which shall
|
|
be non-zero if the argument is a normalized floating-point number and is otherwise unspecified) before the decimal-point character
|
|
and the number of hexadecimal digits after it is equal to the precision; if the precision is missing and FLT_RADIX is a power of 2,
|
|
then the precision shall be sufficient for an exact representation of the value; if the precision is missing and FLT_RADIX is not a
|
|
power of 2, then the precision shall be sufficient to distinguish values of type <b>double</b>, except that trailing zeros may be
|
|
omitted; if the precision is zero and the <tt>'#'</tt> flag is not specified, no decimal-point character shall appear. The letters
|
|
<tt>"abcdef"</tt> shall be used for <tt>a</tt> conversion and the letters <tt>"ABCDEF"</tt> for <tt>A</tt> conversion. The
|
|
<tt>A</tt> conversion specifier produces a number with <tt>'X'</tt> and <tt>'P'</tt> instead of <tt>'x'</tt> and <tt>'p'</tt> . The
|
|
exponent shall always contain at least one digit, and only as many more digits as necessary to represent the decimal exponent of 2.
|
|
If the value is zero, the exponent shall be zero.
|
|
|
|
<p>A <b>double</b> argument representing an infinity or NaN shall be converted in the style of an <tt>f</tt> or <tt>F</tt>
|
|
conversion specifier.</p>
|
|
</dd>
|
|
|
|
<dt><tt>c</tt></dt>
|
|
|
|
<dd>The <b>int</b> argument shall be converted to an <b>unsigned char</b>, and the resulting byte shall be written.
|
|
|
|
<p>If an <tt>l</tt> (ell) qualifier is present, the <b>wint_t</b> argument shall be converted as if by an <tt>ls</tt> conversion
|
|
specification with no precision and an argument that points to a two-element array of type <b>wchar_t</b>, the first element of
|
|
which contains the <b>wint_t</b> argument to the <tt>ls</tt> conversion specification and the second element contains a null wide
|
|
character.</p>
|
|
</dd>
|
|
|
|
<dt><tt>s</tt></dt>
|
|
|
|
<dd>The argument shall be a pointer to an array of <b>char</b>. Bytes from the array shall be written up to (but not including) any
|
|
terminating null byte. If the precision is specified, no more than that many bytes shall be written. If the precision is not
|
|
specified or is greater than the size of the array, the application shall ensure that the array contains a null byte.
|
|
|
|
<p>If an <tt>l</tt> (ell) qualifier is present, the argument shall be a pointer to an array of type <b>wchar_t</b>. Wide characters
|
|
from the array shall be converted to characters (each as if by a call to the <a href=
|
|
"../functions/wcrtomb.html"><i>wcrtomb</i>()</a> function, with the conversion state described by an <b>mbstate_t</b> object
|
|
initialized to zero before the first wide character is converted) up to and including a terminating null wide character. The
|
|
resulting characters shall be written up to (but not including) the terminating null character (byte). If no precision is
|
|
specified, the application shall ensure that the array contains a null wide character. If a precision is specified, no more than
|
|
that many characters (bytes) shall be written (including shift sequences, if any), and the array shall contain a null wide
|
|
character if, to equal the character sequence length given by the precision, the function would need to access a wide character one
|
|
past the end of the array. In no case shall a partial character be written.</p>
|
|
</dd>
|
|
|
|
<dt><tt>p</tt></dt>
|
|
|
|
<dd>The argument shall be a pointer to <b>void</b>. The value of the pointer is converted to a sequence of printable characters, in
|
|
an implementation-defined manner.</dd>
|
|
|
|
<dt><tt>n</tt></dt>
|
|
|
|
<dd>The argument shall be a pointer to an integer into which is written the number of bytes written to the output so far by this
|
|
call to one of the <i>fprintf</i>() functions. No argument is converted.</dd>
|
|
|
|
<dt><tt>C</tt></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Equivalent to <tt>lc</tt> . <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt><tt>S</tt></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Equivalent to <tt>ls</tt> . <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt><tt>%</tt></dt>
|
|
|
|
<dd>Print a <tt>'%'</tt> character; no argument is converted. The complete conversion specification shall be <tt>%%</tt> .</dd>
|
|
</dl>
|
|
|
|
<p>If a conversion specification does not match one of the above forms, the behavior is undefined. If any argument is not the
|
|
correct type for the corresponding conversion specification, the behavior is undefined.</p>
|
|
|
|
<p>In no case shall 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 shall be expanded to contain the conversion result. Characters generated by <i>fprintf</i>() and
|
|
<i>printf</i>() are printed as if <a href="../functions/fputc.html"><i>fputc</i>()</a> had been called.</p>
|
|
|
|
<p>For the <tt>a</tt> and <tt>A</tt> conversion specifiers, if FLT_RADIX is a power of 2, the value shall be correctly rounded to a
|
|
hexadecimal floating number with the given precision.</p>
|
|
|
|
<p>For <tt>a</tt> and <tt>A</tt> conversions, if FLT_RADIX is not a power of 2 and the result is not exactly representable in the
|
|
given precision, the result should be one of the two adjacent numbers in hexadecimal floating style with the given precision, with
|
|
the extra stipulation that the error should have a correct sign for the current rounding direction.</p>
|
|
|
|
<p>For the <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , <tt>F</tt> , <tt>g</tt> , and <tt>G</tt> conversion specifiers, if the number of
|
|
significant decimal digits is at most DECIMAL_DIG, then the result should be correctly rounded. If the number of significant
|
|
decimal digits is more than DECIMAL_DIG but the source value is exactly representable with DECIMAL_DIG digits, then the result
|
|
should be an exact representation with trailing zeros. Otherwise, the source value is bounded by two adjacent decimal strings
|
|
<i>L</i> < <i>U</i>, both having DECIMAL_DIG significant digits; the value of the resultant decimal string <i>D</i> should
|
|
satisfy <i>L</i> <= <i>D</i> <= <i>U</i>, with the extra stipulation that the error should have a correct sign for the
|
|
current rounding direction.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> The
|
|
<i>st_ctime</i> and <i>st_mtime</i> fields of the file shall be marked for update between the call to a successful execution of
|
|
<i>fprintf</i>() or <i>printf</i>() and the next successful completion of a call to <a href=
|
|
"../functions/fflush.html"><i>fflush</i>()</a> or <a href="../functions/fclose.html"><i>fclose</i>()</a> on the same stream or a
|
|
call to <a href="../functions/exit.html"><i>exit</i>()</a> or <a href="../functions/abort.html"><i>abort</i>()</a>. <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, the <i>fprintf</i>() and <i>printf</i>() functions shall return the number of bytes transmitted.</p>
|
|
|
|
<p>Upon successful completion, the <i>sprintf</i>() function shall return the number of bytes written to <i>s</i>, excluding the
|
|
terminating null byte.</p>
|
|
|
|
<p>Upon successful completion, the <i>snprintf</i>() function shall return the number of bytes that would be written to <i>s</i>
|
|
had <i>n</i> been sufficiently large excluding the terminating null byte.</p>
|
|
|
|
<p>If an output error was encountered, these functions shall return a negative value.</p>
|
|
|
|
<p>If the value of <i>n</i> is zero on a call to <i>snprintf</i>(), nothing shall be written, the number of bytes that would have
|
|
been written had <i>n</i> been sufficiently large excluding the terminating null shall be returned, and <i>s</i> may be a null
|
|
pointer.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>For the conditions under which <i>fprintf</i>() and <i>printf</i>() fail and may fail, refer to <a href=
|
|
"fputc.html"><i>fputc</i>()</a> or <a href="fputwc.html"><i>fputwc</i>()</a> .</p>
|
|
|
|
<p>In addition, all forms of <i>fprintf</i>() may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EILSEQ]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
A wide-character code that does not correspond to a valid character has been detected. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
There are insufficient arguments. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
|
|
<p>The <i>printf</i>() and <i>fprintf</i>() functions may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ENOMEM]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Insufficient storage space is available. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
|
|
<p>The <i>snprintf</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EOVERFLOW]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The value of <i>n</i> is greater than {INT_MAX} or the number of bytes needed to hold the output excluding the terminating null is
|
|
greater than {INT_MAX}. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_180_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_03_180_06_01"></a>Printing Language-Independent Date and Time</h5>
|
|
|
|
<p>The following statement can be used to print date and time using a language-independent format:</p>
|
|
|
|
<pre>
|
|
<tt>printf(format, weekday, month, day, hour, min);
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>For American usage, <i>format</i> could be a pointer to the following string:</p>
|
|
|
|
<pre>
|
|
<tt>"%s, %s %d, %d:%.2d\n"
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>This example would produce the following message:</p>
|
|
|
|
<pre>
|
|
<tt>Sunday, July 3, 10:02
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>For German usage, <i>format</i> could be a pointer to the following string:</p>
|
|
|
|
<pre>
|
|
<tt>"%1$s, %3$d. %2$s, %4$d:%5$.2d\n"
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>This definition of <i>format</i> would produce the following message:</p>
|
|
|
|
<pre>
|
|
<tt>Sonntag, 3. Juli, 10:02
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_02"></a>Printing File Information</h5>
|
|
|
|
<p>The following example prints information about the type, permissions, and number of links of a specific file in a directory.</p>
|
|
|
|
<p>The first two calls to <i>printf</i>() use data decoded from a previous <a href="../functions/stat.html"><i>stat</i>()</a> call.
|
|
The user-defined <i>strperm</i>() function shall return a string similar to the one at the beginning of the output for the
|
|
following command:</p>
|
|
|
|
<pre>
|
|
<tt>ls -l
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The next call to <i>printf</i>() outputs the owner's name if it is found using <a href=
|
|
"../functions/getpwuid.html"><i>getpwuid</i>()</a>; the <a href="../functions/getpwuid.html"><i>getpwuid</i>()</a> function shall
|
|
return a <b>passwd</b> structure from which the name of the user is extracted. If the user name is not found, the program instead
|
|
prints out the numeric value of the user ID.</p>
|
|
|
|
<p>The next call prints out the group name if it is found using <a href="../functions/getgrgid.html"><i>getgrgid</i>()</a>; <a
|
|
href="../functions/getgrgid.html"><i>getgrgid</i>()</a> is very similar to <a href=
|
|
"../functions/getpwuid.html"><i>getpwuid</i>()</a> except that it shall return group information based on the group number. Once
|
|
again, if the group is not found, the program prints the numeric value of the group for the entry.</p>
|
|
|
|
<p>The final call to <i>printf</i>() prints the size of the file.</p>
|
|
|
|
<pre>
|
|
<tt>#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <pwd.h>
|
|
#include <grp.h>
|
|
<br>
|
|
char *strperm (mode_t);
|
|
...
|
|
struct stat statbuf;
|
|
struct passwd *pwd;
|
|
struct group *grp;
|
|
...
|
|
printf("%10.10s", strperm (statbuf.st_mode));
|
|
printf("%4d", statbuf.st_nlink);
|
|
<br>
|
|
if ((pwd = getpwuid(statbuf.st_uid)) != NULL)
|
|
printf(" %-8.8s", pwd->pw_name);
|
|
else
|
|
printf(" %-8ld", (long) statbuf.st_uid);
|
|
<br>
|
|
if ((grp = getgrgid(statbuf.st_gid)) != NULL)
|
|
printf(" %-8.8s", grp->gr_name);
|
|
else
|
|
printf(" %-8ld", (long) statbuf.st_gid);
|
|
<br>
|
|
printf("%9jd", (intmax_t) statbuf.st_size);
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_03"></a>Printing a Localized Date String</h5>
|
|
|
|
<p>The following example gets a localized date string. The <a href="../functions/nl_langinfo.html"><i>nl_langinfo</i>()</a>
|
|
function shall return the localized date string, which specifies the order and layout of the date. The <a href=
|
|
"../functions/strftime.html"><i>strftime</i>()</a> function takes this information and, using the <b>tm</b> structure for values,
|
|
places the date and time information into <i>datestring</i>. The <i>printf</i>() function then outputs <i>datestring</i> and the
|
|
name of the entry.</p>
|
|
|
|
<pre>
|
|
<tt>#include <stdio.h>
|
|
#include <time.h>
|
|
#include <langinfo.h>
|
|
...
|
|
struct dirent *dp;
|
|
struct tm *tm;
|
|
char datestring[256];
|
|
...
|
|
strftime(datestring, sizeof(datestring), nl_langinfo (D_T_FMT), tm);
|
|
<br>
|
|
printf(" %s %s\n", datestring, dp->d_name);
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_04"></a>Printing Error Information</h5>
|
|
|
|
<p>The following example uses <i>fprintf</i>() to write error information to standard error.</p>
|
|
|
|
<p>In the first group of calls, the program tries to open the password lock file named <b>LOCKFILE</b>. If the file already exists,
|
|
this is an error, as indicated by the O_EXCL flag on the <a href="../functions/open.html"><i>open</i>()</a> function. If the call
|
|
fails, the program assumes that someone else is updating the password file, and the program exits.</p>
|
|
|
|
<p>The next group of calls saves a new password file as the current password file by creating a link between <b>LOCKFILE</b> and
|
|
the new password file <b>PASSWDFILE</b>.</p>
|
|
|
|
<pre>
|
|
<tt>#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
<br>
|
|
#define LOCKFILE "/etc/ptmp"
|
|
#define PASSWDFILE "/etc/passwd"
|
|
...
|
|
int pfd;
|
|
...
|
|
if ((pfd = open(LOCKFILE, O_WRONLY | O_CREAT | O_EXCL,
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
|
|
{
|
|
fprintf(stderr, "Cannot open /etc/ptmp. Try again later.\n");
|
|
exit(1);
|
|
}
|
|
...
|
|
if (link(LOCKFILE,PASSWDFILE) == -1) {
|
|
fprintf(stderr, "Link error: %s\n", strerror(errno));
|
|
exit(1);
|
|
}
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_05"></a>Printing Usage Information</h5>
|
|
|
|
<p>The following example checks to make sure the program has the necessary arguments, and uses <i>fprintf</i>() to print usage
|
|
information if the expected number of arguments is not present.</p>
|
|
|
|
<pre>
|
|
<tt>#include <stdio.h>
|
|
#include <stdlib.h>
|
|
...
|
|
char *Options = "hdbtl";
|
|
...
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Usage: %s -%s <file\n", argv[0], Options); exit(1);
|
|
}
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_06"></a>Formatting a Decimal String</h5>
|
|
|
|
<p>The following example prints a key and data pair on <i>stdout</i>. Note use of the <tt>'*'</tt> (asterisk) in the format string;
|
|
this ensures the correct number of decimal places for the element based on the number of elements requested.</p>
|
|
|
|
<pre>
|
|
<tt>#include <stdio.h>
|
|
...
|
|
long i;
|
|
char *keystr;
|
|
int elementlen, len;
|
|
...
|
|
while (len < elementlen) {
|
|
...
|
|
printf("%s Element%0*ld\n", keystr, elementlen, i);
|
|
...
|
|
}
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_07"></a>Creating a Filename</h5>
|
|
|
|
<p>The following example creates a filename using information from a previous <a href=
|
|
"../functions/getpwnam.html"><i>getpwnam</i>()</a> function that returned the HOME directory of the user.</p>
|
|
|
|
<pre>
|
|
<tt>#include <stdio.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
...
|
|
char filename[PATH_MAX+1];
|
|
struct passwd *pw;
|
|
...
|
|
sprintf(filename, "%s/%d.out", pw->pw_dir, getpid());
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_08"></a>Reporting an Event</h5>
|
|
|
|
<p>The following example loops until an event has timed out. The <a href="../functions/pause.html"><i>pause</i>()</a> function
|
|
waits forever unless it receives a signal. The <i>fprintf</i>() statement should never occur due to the possible return values of
|
|
<a href="../functions/pause.html"><i>pause</i>()</a>.</p>
|
|
|
|
<pre>
|
|
<tt>#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
...
|
|
while (!event_complete) {
|
|
...
|
|
if (pause() != -1 || errno != EINTR)
|
|
fprintf(stderr, "pause: unknown error: %s\n", strerror(errno));
|
|
}
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_09"></a>Printing Monetary Information</h5>
|
|
|
|
<p>The following example uses <a href="../functions/strfmon.html"><i>strfmon</i>()</a> to convert a number and store it as a
|
|
formatted monetary string named <i>convbuf</i>. If the first number is printed, the program prints the format and the description;
|
|
otherwise, it just prints the number.</p>
|
|
|
|
<pre>
|
|
<tt>#include <monetary.h>
|
|
#include <stdio.h>
|
|
...
|
|
struct tblfmt {
|
|
char *format;
|
|
char *description;
|
|
};
|
|
<br>
|
|
struct tblfmt table[] = {
|
|
{ "%n", "default formatting" },
|
|
{ "%11n", "right align within an 11 character field" },
|
|
{ "%#5n", "aligned columns for values up to 99999" },
|
|
{ "%=*#5n", "specify a fill character" },
|
|
{ "%=0#5n", "fill characters do not use grouping" },
|
|
{ "%^#5n", "disable the grouping separator" },
|
|
{ "%^#5.0n", "round off to whole units" },
|
|
{ "%^#5.4n", "increase the precision" },
|
|
{ "%(#5n", "use an alternative pos/neg style" },
|
|
{ "%!(#5n", "disable the currency symbol" },
|
|
};
|
|
...
|
|
float input[3];
|
|
int i, j;
|
|
char convbuf[100];
|
|
...
|
|
strfmon(convbuf, sizeof(convbuf), table[i].format, input[j]);
|
|
<br>
|
|
if (j == 0) {
|
|
printf("%s %s %s\n", table[i].format,
|
|
convbuf, table[i].description);
|
|
}
|
|
else {
|
|
printf(" %s\n", convbuf);
|
|
}
|
|
...
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_03_180_06_10"></a>Printing Wide Characters</h5>
|
|
|
|
<p>The following example prints a series of wide characters. Suppose that <tt>"L`@`"</tt> expands to three bytes:</p>
|
|
|
|
<pre>
|
|
<tt>wchar_t wz [3] = L"@@"; // Zero-terminated
|
|
wchar_t wn [3] = L"@@@"; // Unterminated
|
|
<br>
|
|
fprintf (stdout,"%ls", wz); // Outputs 6 bytes
|
|
fprintf (stdout,"%ls", wn); // Undefined because wn has no terminator
|
|
fprintf (stdout,"%4ls", wz); // Outputs 3 bytes
|
|
fprintf (stdout,"%4ls", wn); // Outputs 3 bytes; no terminator needed
|
|
fprintf (stdout,"%9ls", wz); // Outputs 6 bytes
|
|
fprintf (stdout,"%9ls", wn); // Outputs 9 bytes; no terminator needed
|
|
fprintf (stdout,"%10ls", wz); // Outputs 6 bytes
|
|
fprintf (stdout,"%10ls", wn); // Undefined because wn has no terminator
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>In the last line of the example, after processing three characters, nine bytes have been output. The fourth character must then
|
|
be examined to determine whether it converts to one byte or more. If it converts to more than one byte, the output is only nine
|
|
bytes. Since there is no fourth character in the array, the behavior is undefined.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>If the application calling <i>fprintf</i>() has any objects of type <b>wint_t</b> or <b>wchar_t</b>, it must also include the <a
|
|
href="../basedefs/wchar.h.html"><i><wchar.h></i></a> header to have these objects defined.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="fputc.html"><i>fputc</i>()</a> , <a href="fscanf.html"><i>fscanf</i>()</a> , <a href=
|
|
"setlocale.html"><i>setlocale</i>()</a> , <a href="strfmon.html"><i>strfmon</i>()</a> , <a href="wcrtomb.html"><i>wcrtomb</i>()</a>
|
|
, the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap07.html">Chapter 7, Locale</a>, <a
|
|
href="../basedefs/stdio.h.html"><i><stdio.h></i></a>, <a href="../basedefs/wchar.h.html"><i><wchar.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>Aligned with ISO/IEC 9899:1990/Amendment 1:1995 (E). Specifically, the <tt>l</tt> (ell) qualifier can now be used with
|
|
<tt>c</tt> and <tt>s</tt> conversion specifiers.</p>
|
|
|
|
<p>The <i>snprintf</i>() function is new in Issue 5.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_180_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>Extensions beyond the ISO C standard are marked.</p>
|
|
|
|
<p>The DESCRIPTION is updated to avoid use of the term "must" for application requirements.</p>
|
|
|
|
<p>The following changes are made for alignment with the ISO/IEC 9899:1999 standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The prototypes for <i>fprintf</i>(), <i>printf</i>(), <i>snprintf</i>(), and <i>sprintf</i>() are updated, and the XSI shading
|
|
is removed from <i>snprintf</i>().</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The description of <i>snprintf</i>() is aligned with the ISO C standard. Note that this supersedes the <i>snprintf</i>()
|
|
description in The Open Group Base Resolution bwg98-006, which changed the behavior from Issue 5.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The DESCRIPTION is updated.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The DESCRIPTION is updated to use the terms "conversion specifier" and "conversion specification" consistently.</p>
|
|
|
|
<p>ISO/IEC 9899:1999 standard, Technical Corrigendum No. 1 is incorporated.</p>
|
|
|
|
<p>An example of printing wide characters is added.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|