⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xbd_chap05.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</td><td align="left"><p class="tent">Move the printing position to the start of the next vertical tab position. If there are no more vertical tabpositions left on the page, the behavior is undefined.</p></td></tr></table></center><p>Each conversion specification is introduced by the percent-sign character ( <tt>'%'</tt> ). After the character <tt>'%'</tt> ,the following shall appear in sequence:</p><dl compact><dt><i>flags</i></dt><dd>Zero or more <i>flags</i>, in any order, that modify the meaning of the conversion specification.</dd><dt><i>field&nbsp;width</i></dt><dd>An optional string of decimal digits to specify a minimum field width. For an output field, if the converted value has fewerbytes than the field width, it shall be padded on the left (or right, if the left-adjustment flag ( <tt>'-'</tt> ), describedbelow, has been given) to the field width.</dd><dt><i>precision</i></dt><dd>Gives the minimum number of digits to appear for the <tt>d</tt> , <tt>o</tt> , <tt>i</tt> , <tt>u</tt> , <tt>x</tt> , or<tt>X</tt> conversion specifiers (the field is padded with leading zeros), the number of digits to appear after the radix characterfor the <tt>e</tt> and <tt>f</tt> conversion specifiers, the maximum number of significant digits for the <tt>g</tt> conversionspecifier; or the maximum number of bytes to be written from a string in the <tt>s</tt> conversion specifier. The precision shalltake the form of a period ( <tt>'.'</tt> ) followed by a decimal digit string; a null digit string is treated as zero.</dd><dt><i>conversion specifier characters</i></dt><dd><br>A conversion specifier character (see below) that indicates the type of conversion to be applied.</dd></dl><p>The <i>flag</i> characters and their meanings are:</p><dl compact><dt><tt>-</tt></dt><dd>The result of the conversion shall be left-justified within the field.</dd><dt><tt>+</tt></dt><dd>The result of a signed conversion shall always begin with a sign ( <tt>'+'</tt> or <tt>'-'</tt> ).</dd><dt>&lt;space&gt;</dt><dd>If the first character of a signed conversion is not a sign, a &lt;space&gt; shall be prefixed to the result. This means thatif the &lt;space&gt; and <tt>'+'</tt> flags both appear, the &lt;space&gt; flag shall be ignored.</dd><dt><tt>#</tt></dt><dd>The value shall be converted to an alternative form. For <tt>c</tt> , <tt>d</tt> , <tt>i</tt> , <tt>u</tt> , and <tt>s</tt>conversion specifiers, the behavior is undefined. For the <tt>o</tt> conversion specifier, it shall increase the precision to forcethe first digit of the result to be a zero. For <tt>x</tt> or <tt>X</tt> conversion specifiers, a non-zero result has 0x or 0Xprefixed to it, respectively. For <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , <tt>g</tt> , and <tt>G</tt> conversion specifiers, theresult shall always contain a radix character, even if no digits follow the radix character. For <tt>g</tt> and <tt>G</tt>conversion specifiers, trailing zeros shall not be removed from the result as they usually are.</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>e</tt> , <tt>E</tt> , <tt>f</tt> ,<tt>g</tt> , and <tt>G</tt> conversion specifiers, leading zeros (following any indication of sign or base) shall be used to pad tothe field width; no space padding is performed. If the <tt>'0'</tt> and <tt>'-'</tt> flags both appear, the <tt>'0'</tt> flag shallbe ignored. For <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , and <tt>X</tt> conversion specifiers, if aprecision is specified, the <tt>'0'</tt> flag shall be ignored. For other conversion specifiers, the behavior is undefined.</dd></dl><p>Each conversion specifier character shall result in fetching zero or more arguments. The results are undefined if there areinsufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments shall beignored.</p><p>The conversion specifiers and their meanings are:</p><dl compact><dt><tt>d</tt>,<tt>i</tt>,<tt>o</tt>,<tt>u</tt>,<tt>x</tt>,<tt>X</tt></dt><dd>The integer argument shall be written as signed decimal ( <tt>d</tt> or <tt>i</tt> ), unsigned octal ( <tt>o</tt> ), unsigneddecimal ( <tt>u</tt> ), or unsigned hexadecimal notation ( <tt>x</tt> and <tt>X</tt> ). The <tt>d</tt> and <tt>i</tt> specifiersshall convert to signed decimal in the style <tt>"[-]</tt><i>dddd</i><tt>"</tt>. The <tt>x</tt> conversion specifier shall use thenumbers and letters <tt>"0123456789abcdef"</tt> and the <tt>X</tt> conversion specifier shall use the numbers and letters<tt>"0123456789ABCDEF"</tt> . The <i>precision</i> component of the argument shall specify the minimum number of digits to appear.If the value being converted can be represented in fewer digits than the specified minimum, it shall be expanded with leadingzeros. The default precision shall be 1. The result of converting a zero value with a precision of 0 shall be no characters. Ifboth the field width and precision are omitted, the implementation may precede, follow, or precede and follow numeric arguments oftypes <tt>d</tt> , <tt>i</tt> , and <tt>u</tt> with &lt;blank&gt;s; arguments of type <tt>o</tt> (octal) may be preceded withleading zeros.</dd><dt><tt>f</tt></dt><dd>The floating-point number argument shall be written in decimal notation in the style <b>[</b>-<b>]</b><i>ddd.ddd</i>, where thenumber of digits after the radix character (shown here as a decimal point) shall be equal to the <i>precision</i> specification.The <i>LC_NUMERIC</i> locale category shall determine the radix character to use in this format. If the <i>precision</i> is omittedfrom the argument, six digits shall be written after the radix character; if the <i>precision</i> is explicitly 0, no radixcharacter shall appear.</dd><dt><tt>e</tt>,<tt>E</tt></dt><dd>The floating-point number argument shall be written in the style <b>[</b>-<b>]</b><i>d.ddd</i>e<i>&plusmn;dd</i> (the symbol<tt>'&plusmn;'</tt> indicates either a plus or minus sign), where there is one digit before the radix character (shown here as adecimal point) and the number of digits after it is equal to the precision. The <i>LC_NUMERIC</i> locale category shall determinethe radix character to use in this format. When the precision is missing, six digits shall be written after the radix character; ifthe precision is 0, no radix character shall appear. 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. However, if the value to bewritten requires an exponent greater than two digits, additional exponent digits shall be written as necessary.</dd><dt><tt>g</tt>,<tt>G</tt></dt><dd>The floating-point number argument shall be written in style <tt>f</tt> or <tt>e</tt> (or in style <tt>F</tt> or <tt>E</tt> inthe case of a <tt>G</tt> conversion specifier), with the precision specifying the number of significant digits. The style useddepends on the value converted: style <tt>e</tt> (or <tt>E</tt> ) shall be used only if the exponent resulting from the conversionis less than -4 or greater than or equal to the precision. Trailing zeros are removed from the result. A radix character shallappear only if it is followed by a digit.</dd><dt><tt>c</tt></dt><dd>The integer argument shall be converted to an <b>unsigned char</b> and the resulting byte shall be written.</dd><dt><tt>s</tt></dt><dd>The argument shall be taken to be a string and bytes from the string shall be written until the end of the string or the numberof bytes indicated by the <i>precision</i> specification of the argument is reached. If the precision is omitted from the argument,it shall be taken to be infinite, so all bytes up to the end of the string shall be written.</dd><dt><tt>%</tt></dt><dd>Write a <tt>'%'</tt> character; no argument is converted.</dd></dl><p>In no case does a nonexistent or insufficient field width cause truncation of a field; if the result of a conversion is widerthan the field width, the field is simply expanded to contain the conversion result. The term &quot;field width&quot; should not beconfused with the term &quot;precision&quot; used in the description of <tt>%s</tt> .</p><hr><div class="box"><em>The following sections are informative.</em></div><h5><a name="tag_05_00_00_01"></a>Examples</h5><p>To represent the output of a program that prints a date and time in the form Sunday, July 3, 10:02, where <i>weekday</i> and<i>month</i> are strings:</p><blockquote><pre><tt>"%s,<img src="../images/delta.gif" border="0">%s<img src="../images/delta.gif" border="0">%d,<img src="../images/delta.gif"border="0">%d:%.2d\n" &lt;</tt><i>weekday</i><tt>&gt;, &lt;</tt><i>month</i><tt>&gt;, &lt;</tt><i>day</i><tt>&gt;, &lt;</tt><i>hour</i><tt>&gt;, &lt;</tt><i>min</i><tt>&gt;</tt></pre></blockquote><p>To show <tt>'<img src="../images/pi.gif" border="0">'</tt> written to 5 decimal places:</p><blockquote><pre><tt>"pi<img src="../images/delta.gif" border="0">=<img src="../images/delta.gif" border="0">%.5f\n",&lt;</tt><i>value of</i> <tt><img src="../images/pi.gif" border="0">&gt;</tt></pre></blockquote><p>To show an input file format consisting of five colon-separated fields:</p><blockquote><pre><tt>"%s:%s:%s:%s:%s\n", &lt;</tt><i>arg1</i><tt>&gt;, &lt;</tt><i>arg2</i><tt>&gt;, &lt;</tt><i>arg3</i><tt>&gt;, &lt;</tt><i>arg4</i><tt>&gt;, &lt;</tt><i>arg5</i><tt>&gt;</tt></pre></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; 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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -