Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

swprintf.html 24KB

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>swprintf (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="swprintf (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="swprintf (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdio.html#Stdio" rel="up" title="Stdio">
  16. <link href="swscanf.html#swscanf" rel="next" title="swscanf">
  17. <link href="stdio_005fext.html#stdio_005fext" rel="prev" title="stdio_ext">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="swprintf"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="swscanf.html#swscanf" accesskey="n" rel="next">swscanf</a>, Previous: <a href="stdio_005fext.html#stdio_005fext" accesskey="p" rel="prev">stdio_ext</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="swprintf_002c-fwprintf_002c-wprintf_002d_002d_002dwide-character-format-output"></a>
  54. <h3 class="section">4.64 <code>swprintf</code>, <code>fwprintf</code>, <code>wprintf</code>&mdash;wide character format output</h3>
  55. <a name="index-fwprintf"></a>
  56. <a name="index-_005ffwprintf_005fr"></a>
  57. <a name="index-wprintf"></a>
  58. <a name="index-_005fwprintf_005fr"></a>
  59. <a name="index-swprintf"></a>
  60. <a name="index-_005fswprintf_005fr"></a>
  61. <p><strong>Synopsis</strong>
  62. </p><div class="example">
  63. <pre class="example">#include &lt;wchar.h&gt;
  64. int wprintf(const wchar_t *<var>format</var>, ...);
  65. int fwprintf(FILE *__restrict <var>fd</var>,
  66. const wchar_t *__restrict <var>format</var>, ...);
  67. int swprintf(wchar_t *__restrict <var>str</var>, size_t <var>size</var>,
  68. const wchar_t *__restrict <var>format</var>, ...);
  69. int _wprintf_r(struct _reent *<var>ptr</var>, const wchar_t *<var>format</var>, ...);
  70. int _fwprintf_r(struct _reent *<var>ptr</var>, FILE *<var>fd</var>,
  71. const wchar_t *<var>format</var>, ...);
  72. int _swprintf_r(struct _reent *<var>ptr</var>, wchar_t *<var>str</var>,
  73. size_t <var>size</var>, const wchar_t *<var>format</var>, ...);
  74. </pre></div>
  75. <p><strong>Description</strong><br>
  76. <code>wprintf</code> accepts a series of arguments, applies to each a
  77. format specifier from <code>*<var>format</var></code>, and writes the
  78. formatted data to <code>stdout</code>, without a terminating NUL
  79. wide character. The behavior of <code>wprintf</code> is undefined if there
  80. are not enough arguments for the format or if any argument is not the
  81. right type for the corresponding conversion specifier. <code>wprintf</code>
  82. returns when it reaches the end of the format string. If there are
  83. more arguments than the format requires, excess arguments are
  84. ignored.
  85. </p>
  86. <p><code>fwprintf</code> is like <code>wprintf</code>, except that output is directed
  87. to the stream <var>fd</var> rather than <code>stdout</code>.
  88. </p>
  89. <p><code>swprintf</code> is like <code>wprintf</code>, except that output is directed
  90. to the buffer <var>str</var> with a terminating wide <code>NUL</code>, and the
  91. resulting string length is limited to at most <var>size</var> wide characters,
  92. including the terminating <code>NUL</code>. It is considered an error if the
  93. output (including the terminating wide-<code>NULL</code>) does not fit into
  94. <var>size</var> wide characters. (This error behavior is not the same as for
  95. <code>snprintf</code>, which <code>swprintf</code> is otherwise completely analogous to.
  96. While <code>snprintf</code> allows the needed size to be known simply by giving
  97. <var>size</var>=0, <code>swprintf</code> does not, giving an error instead.)
  98. </p>
  99. <p>For <code>swprintf</code> the behavior is undefined if the output
  100. <code>*<var>str</var></code> overlaps with one of the arguments. Behavior is also
  101. undefined if the argument for <code>%n</code> within <code>*<var>format</var></code>
  102. overlaps another argument.
  103. </p>
  104. <p><var>format</var> is a pointer to a wide character string containing two
  105. types of objects: ordinary characters (other than <code>%</code>),
  106. which are copied unchanged to the output, and conversion
  107. specifications, each of which is introduced by <code>%</code>. (To
  108. include <code>%</code> in the output, use <code>%%</code> in the format string.)
  109. A conversion specification has the following form:
  110. </p>
  111. <div class="smallexample">
  112. <pre class="smallexample"> %[<var>pos</var>][<var>flags</var>][<var>width</var>][.<var>prec</var>][<var>size</var>]<var>type</var>
  113. </pre></div>
  114. <p>The fields of the conversion specification have the following
  115. meanings:
  116. </p>
  117. <ul>
  118. <li> <var>pos</var>
  119. <p>Conversions normally consume arguments in the order that they
  120. are presented. However, it is possible to consume arguments
  121. out of order, and reuse an argument for more than one
  122. conversion specification (although the behavior is undefined
  123. if the same argument is requested with different types), by
  124. specifying <var>pos</var>, which is a decimal integer followed by
  125. &rsquo;$&rsquo;. The integer must be between 1 and &lt;NL_ARGMAX&gt; from
  126. limits.h, and if argument <code>%n$</code> is requested, all earlier
  127. arguments must be requested somewhere within <var>format</var>. If
  128. positional parameters are used, then all conversion
  129. specifications except for <code>%%</code> must specify a position.
  130. This positional parameters method is a POSIX extension to the C
  131. standard definition for the functions.
  132. </p>
  133. </li><li> <var>flags</var>
  134. <p><var>flags</var> is an optional sequence of characters which control
  135. output justification, numeric signs, decimal points, trailing
  136. zeros, and octal and hex prefixes. The flag characters are
  137. minus (<code>-</code>), plus (<code>+</code>), space ( ), zero (<code>0</code>), sharp
  138. (<code>#</code>), and quote (<code>'</code>). They can appear in any
  139. combination, although not all flags can be used for all
  140. conversion specification types.
  141. </p>
  142. <dl compact="compact">
  143. <dt><code>'</code></dt>
  144. <dd><p>A POSIX extension to the C standard. However, this
  145. implementation presently treats it as a no-op, which
  146. is the default behavior for the C locale, anyway. (If
  147. it did what it is supposed to, when <var>type</var> were <code>i</code>,
  148. <code>d</code>, <code>u</code>, <code>f</code>, <code>F</code>, <code>g</code>, or <code>G</code>, the
  149. integer portion of the conversion would be formatted
  150. with thousands&rsquo; grouping wide characters.)
  151. </p>
  152. </dd>
  153. <dt><code>-</code></dt>
  154. <dd><p>The result of the conversion is left
  155. justified, and the right is padded with
  156. blanks. If you do not use this flag, the
  157. result is right justified, and padded on the
  158. left.
  159. </p>
  160. </dd>
  161. <dt><code>+</code></dt>
  162. <dd><p>The result of a signed conversion (as
  163. determined by <var>type</var> of <code>d</code>, <code>i</code>, <code>a</code>,
  164. <code>A</code>, <code>e</code>, <code>E</code>, <code>f</code>, <code>F</code>, <code>g</code>, or
  165. <code>G</code>) will always begin with a plus or minus
  166. sign. (If you do not use this flag, positive
  167. values do not begin with a plus sign.)
  168. </p>
  169. </dd>
  170. <dt><code>&quot; &quot; (space)</code></dt>
  171. <dd><p>If the first character of a signed conversion
  172. specification is not a sign, or if a signed
  173. conversion results in no characters, the
  174. result will begin with a space. If the space
  175. ( ) flag and the plus (<code>+</code>) flag both
  176. appear, the space flag is ignored.
  177. </p>
  178. </dd>
  179. <dt><code>0</code></dt>
  180. <dd><p>If the <var>type</var> character is <code>d</code>, <code>i</code>,
  181. <code>o</code>, <code>u</code>, <code>x</code>, <code>X</code>, <code>a</code>, <code>A</code>,
  182. <code>e</code>, <code>E</code>, <code>f</code>, <code>F</code>, <code>g</code>, or <code>G</code>: leading
  183. zeros are used to pad the field width
  184. (following any indication of sign or base); no
  185. spaces are used for padding. If the zero
  186. (<code>0</code>) and minus (<code>-</code>) flags both appear,
  187. the zero (<code>0</code>) flag will be ignored. For
  188. <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, and <code>X</code>
  189. conversions, if a precision <var>prec</var> is
  190. specified, the zero (<code>0</code>) flag is ignored.
  191. </p>
  192. <p>Note that <code>0</code> is interpreted as a flag, not
  193. as the beginning of a field width.
  194. </p>
  195. </dd>
  196. <dt><code>#</code></dt>
  197. <dd><p>The result is to be converted to an
  198. alternative form, according to the <var>type</var>
  199. character.
  200. </p></dd>
  201. </dl>
  202. <p>The alternative form output with the # flag depends on the <var>type</var>
  203. character:
  204. </p>
  205. <dl compact="compact">
  206. <dt><code>o</code></dt>
  207. <dd><p>Increases precision to force the first
  208. digit of the result to be a zero.
  209. </p>
  210. </dd>
  211. <dt><code>x</code></dt>
  212. <dd><p>A non-zero result will have a <code>0x</code>
  213. prefix.
  214. </p>
  215. </dd>
  216. <dt><code>X</code></dt>
  217. <dd><p>A non-zero result will have a <code>0X</code>
  218. prefix.
  219. </p>
  220. </dd>
  221. <dt><code>a, A, e, E, f, or F</code></dt>
  222. <dd><p>The result will always contain a
  223. decimal point even if no digits follow
  224. the point. (Normally, a decimal point
  225. appears only if a digit follows it.)
  226. Trailing zeros are removed.
  227. </p>
  228. </dd>
  229. <dt><code>g or G</code></dt>
  230. <dd><p>The result will always contain a
  231. decimal point even if no digits follow
  232. the point. Trailing zeros are not
  233. removed.
  234. </p>
  235. </dd>
  236. <dt><code>all others</code></dt>
  237. <dd><p>Undefined.
  238. </p>
  239. </dd>
  240. </dl>
  241. </li><li> <var>width</var>
  242. <p><var>width</var> is an optional minimum field width. You can
  243. either specify it directly as a decimal integer, or
  244. indirectly by using instead an asterisk (<code>*</code>), in
  245. which case an <code>int</code> argument is used as the field
  246. width. If positional arguments are used, then the
  247. width must also be specified positionally as <code>*m$</code>,
  248. with m as a decimal integer. Negative field widths
  249. are treated as specifying the minus (<code>-</code>) flag for
  250. left justfication, along with a positive field width.
  251. The resulting format may be wider than the specified
  252. width.
  253. </p>
  254. </li><li> <var>prec</var>
  255. <p><var>prec</var> is an optional field; if present, it is
  256. introduced with &lsquo;<code>.</code>&rsquo; (a period). You can specify
  257. the precision either directly as a decimal integer or
  258. indirectly by using an asterisk (<code>*</code>), in which case
  259. an <code>int</code> argument is used as the precision. If
  260. positional arguments are used, then the precision must
  261. also be specified positionally as <code>*m$</code>, with m as a
  262. decimal integer. Supplying a negative precision is
  263. equivalent to omitting the precision. If only a
  264. period is specified the precision is zero. The effect
  265. depends on the conversion <var>type</var>.
  266. </p>
  267. <dl compact="compact">
  268. <dt><code>d, i, o, u, x, or X</code></dt>
  269. <dd><p>Minimum number of digits to appear. If no
  270. precision is given, defaults to 1.
  271. </p>
  272. </dd>
  273. <dt><code>a or A</code></dt>
  274. <dd><p>Number of digits to appear after the decimal
  275. point. If no precision is given, the
  276. precision defaults to the minimum needed for
  277. an exact representation.
  278. </p>
  279. </dd>
  280. <dt><code>e, E, f or F</code></dt>
  281. <dd><p>Number of digits to appear after the decimal
  282. point. If no precision is given, the
  283. precision defaults to 6.
  284. </p>
  285. </dd>
  286. <dt><code>g or G</code></dt>
  287. <dd><p>Maximum number of significant digits. A
  288. precision of 0 is treated the same as a
  289. precision of 1. If no precision is given, the
  290. precision defaults to 6.
  291. </p>
  292. </dd>
  293. <dt><code>s or S</code></dt>
  294. <dd><p>Maximum number of characters to print from the
  295. string. If no precision is given, the entire
  296. string is printed.
  297. </p>
  298. </dd>
  299. <dt><code>all others</code></dt>
  300. <dd><p>undefined.
  301. </p>
  302. </dd>
  303. </dl>
  304. </li><li> <var>size</var>
  305. <p><var>size</var> is an optional modifier that changes the data
  306. type that the corresponding argument has. Behavior is
  307. unspecified if a size is given that does not match the
  308. <var>type</var>.
  309. </p>
  310. <dl compact="compact">
  311. <dt><code>hh</code></dt>
  312. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  313. <code>X</code>, specifies that the argument should be
  314. converted to a <code>signed char</code> or <code>unsigned
  315. char</code> before printing.
  316. </p>
  317. <p>With <code>n</code>, specifies that the argument is a
  318. pointer to a <code>signed char</code>.
  319. </p>
  320. </dd>
  321. <dt><code>h</code></dt>
  322. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  323. <code>X</code>, specifies that the argument should be
  324. converted to a <code>short</code> or <code>unsigned short</code>
  325. before printing.
  326. </p>
  327. <p>With <code>n</code>, specifies that the argument is a
  328. pointer to a <code>short</code>.
  329. </p>
  330. </dd>
  331. <dt><code>l</code></dt>
  332. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  333. <code>X</code>, specifies that the argument is a
  334. <code>long</code> or <code>unsigned long</code>.
  335. </p>
  336. <p>With <code>c</code>, specifies that the argument has
  337. type <code>wint_t</code>.
  338. </p>
  339. <p>With <code>s</code>, specifies that the argument is a
  340. pointer to <code>wchar_t</code>.
  341. </p>
  342. <p>With <code>n</code>, specifies that the argument is a
  343. pointer to a <code>long</code>.
  344. </p>
  345. <p>With <code>a</code>, <code>A</code>, <code>e</code>, <code>E</code>, <code>f</code>, <code>F</code>,
  346. <code>g</code>, or <code>G</code>, has no effect (because of
  347. vararg promotion rules, there is no need to
  348. distinguish between <code>float</code> and <code>double</code>).
  349. </p>
  350. </dd>
  351. <dt><code>ll</code></dt>
  352. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  353. <code>X</code>, specifies that the argument is a
  354. <code>long long</code> or <code>unsigned long long</code>.
  355. </p>
  356. <p>With <code>n</code>, specifies that the argument is a
  357. pointer to a <code>long long</code>.
  358. </p>
  359. </dd>
  360. <dt><code>j</code></dt>
  361. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  362. <code>X</code>, specifies that the argument is an
  363. <code>intmax_t</code> or <code>uintmax_t</code>.
  364. </p>
  365. <p>With <code>n</code>, specifies that the argument is a
  366. pointer to an <code>intmax_t</code>.
  367. </p>
  368. </dd>
  369. <dt><code>z</code></dt>
  370. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  371. <code>X</code>, specifies that the argument is a <code>size_t</code>.
  372. </p>
  373. <p>With <code>n</code>, specifies that the argument is a
  374. pointer to a <code>size_t</code>.
  375. </p>
  376. </dd>
  377. <dt><code>t</code></dt>
  378. <dd><p>With <code>d</code>, <code>i</code>, <code>o</code>, <code>u</code>, <code>x</code>, or
  379. <code>X</code>, specifies that the argument is a
  380. <code>ptrdiff_t</code>.
  381. </p>
  382. <p>With <code>n</code>, specifies that the argument is a
  383. pointer to a <code>ptrdiff_t</code>.
  384. </p>
  385. </dd>
  386. <dt><code>L</code></dt>
  387. <dd><p>With <code>a</code>, <code>A</code>, <code>e</code>, <code>E</code>, <code>f</code>, <code>F</code>,
  388. <code>g</code>, or <code>G</code>, specifies that the argument
  389. is a <code>long double</code>.
  390. </p>
  391. </dd>
  392. </dl>
  393. </li><li> <var>type</var>
  394. <p><var>type</var> specifies what kind of conversion <code>wprintf</code>
  395. performs. Here is a table of these:
  396. </p>
  397. <dl compact="compact">
  398. <dt><code>%</code></dt>
  399. <dd><p>Prints the percent character (<code>%</code>).
  400. </p>
  401. </dd>
  402. <dt><code>c</code></dt>
  403. <dd><p>If no <code>l</code> qualifier is present, the int argument shall
  404. be converted to a wide character as if by calling
  405. the btowc() function and the resulting wide character
  406. shall be written. Otherwise, the wint_t argument
  407. shall be converted to wchar_t, and written.
  408. </p>
  409. </dd>
  410. <dt><code>C</code></dt>
  411. <dd><p>Short for <code>%lc</code>. A POSIX extension to the C standard.
  412. </p>
  413. </dd>
  414. <dt><code>s</code></dt>
  415. <dd><p>If no <code>l</code> qualifier is present, the application
  416. shall ensure that the argument is a pointer to a
  417. character array containing a character sequence
  418. beginning in the initial shift state. Characters
  419. from the array shall be converted as if by repeated
  420. calls to the mbrtowc() function, with the conversion
  421. state described by an mbstate_t object initialized to
  422. zero before the first character is converted, and
  423. written up to (but not including) the terminating
  424. null wide character. If the precision is specified,
  425. no more than that many wide characters shall be
  426. written. If the precision is not specified, or is
  427. greater than the size of the array, the application
  428. shall ensure that the array contains a null wide
  429. character.
  430. </p>
  431. <p>If an <code>l</code> qualifier is present, the application
  432. shall ensure that the argument is a pointer to an
  433. array of type wchar_t. Wide characters from the array
  434. shall be written up to (but not including) a
  435. terminating null wide character. If no precision is
  436. specified, or is greater than the size of the array,
  437. the application shall ensure that the array contains
  438. a null wide character. If a precision is specified,
  439. no more than that many wide characters shall be
  440. written.
  441. </p>
  442. </dd>
  443. <dt><code>S</code></dt>
  444. <dd><p>Short for <code>%ls</code>. A POSIX extension to the C standard.
  445. </p>
  446. </dd>
  447. <dt><code>d or i</code></dt>
  448. <dd><p>Prints a signed decimal integer; takes an
  449. <code>int</code>. Leading zeros are inserted as
  450. necessary to reach the precision. A value of 0 with
  451. a precision of 0 produces an empty string.
  452. </p>
  453. </dd>
  454. <dt><code>o</code></dt>
  455. <dd><p>Prints an unsigned octal integer; takes an
  456. <code>unsigned</code>. Leading zeros are inserted as
  457. necessary to reach the precision. A value of 0 with
  458. a precision of 0 produces an empty string.
  459. </p>
  460. </dd>
  461. <dt><code>u</code></dt>
  462. <dd><p>Prints an unsigned decimal integer; takes an
  463. <code>unsigned</code>. Leading zeros are inserted as
  464. necessary to reach the precision. A value of 0 with
  465. a precision of 0 produces an empty string.
  466. </p>
  467. </dd>
  468. <dt><code>x</code></dt>
  469. <dd><p>Prints an unsigned hexadecimal integer (using
  470. <code>abcdef</code> as digits beyond <code>9</code>); takes an
  471. <code>unsigned</code>. Leading zeros are inserted as
  472. necessary to reach the precision. A value of 0 with
  473. a precision of 0 produces an empty string.
  474. </p>
  475. </dd>
  476. <dt><code>X</code></dt>
  477. <dd><p>Like <code>x</code>, but uses <code>ABCDEF</code> as digits
  478. beyond <code>9</code>.
  479. </p>
  480. </dd>
  481. <dt><code>f</code></dt>
  482. <dd><p>Prints a signed value of the form
  483. <code>[-]9999.9999</code>, with the precision
  484. determining how many digits follow the decimal
  485. point; takes a <code>double</code> (remember that
  486. <code>float</code> promotes to <code>double</code> as a vararg).
  487. The low order digit is rounded to even. If
  488. the precision results in at most DECIMAL_DIG
  489. digits, the result is rounded correctly; if
  490. more than DECIMAL_DIG digits are printed, the
  491. result is only guaranteed to round back to the
  492. original value.
  493. </p>
  494. <p>If the value is infinite, the result is
  495. <code>inf</code>, and no zero padding is performed. If
  496. the value is not a number, the result is
  497. <code>nan</code>, and no zero padding is performed.
  498. </p>
  499. </dd>
  500. <dt><code>F</code></dt>
  501. <dd><p>Like <code>f</code>, but uses <code>INF</code> and <code>NAN</code> for
  502. non-finite numbers.
  503. </p>
  504. </dd>
  505. <dt><code>e</code></dt>
  506. <dd><p>Prints a signed value of the form
  507. <code>[-]9.9999e[+|-]999</code>; takes a <code>double</code>.
  508. The digit before the decimal point is non-zero
  509. if the value is non-zero. The precision
  510. determines how many digits appear between
  511. <code>.</code> and <code>e</code>, and the exponent always
  512. contains at least two digits. The value zero
  513. has an exponent of zero. If the value is not
  514. finite, it is printed like <code>f</code>.
  515. </p>
  516. </dd>
  517. <dt><code>E</code></dt>
  518. <dd><p>Like <code>e</code>, but using <code>E</code> to introduce the
  519. exponent, and like <code>F</code> for non-finite
  520. values.
  521. </p>
  522. </dd>
  523. <dt><code>g</code></dt>
  524. <dd><p>Prints a signed value in either <code>f</code> or <code>e</code>
  525. form, based on the given value and
  526. precision&mdash;an exponent less than -4 or
  527. greater than the precision selects the <code>e</code>
  528. form. Trailing zeros and the decimal point
  529. are printed only if necessary; takes a
  530. <code>double</code>.
  531. </p>
  532. </dd>
  533. <dt><code>G</code></dt>
  534. <dd><p>Like <code>g</code>, except use <code>F</code> or <code>E</code> form.
  535. </p>
  536. </dd>
  537. <dt><code>a</code></dt>
  538. <dd><p>Prints a signed value of the form
  539. <code>[-]0x1.ffffp[+|-]9</code>; takes a <code>double</code>.
  540. The letters <code>abcdef</code> are used for digits
  541. beyond <code>9</code>. The precision determines how
  542. many digits appear after the decimal point.
  543. The exponent contains at least one digit, and
  544. is a decimal value representing the power of
  545. 2; a value of 0 has an exponent of 0.
  546. Non-finite values are printed like <code>f</code>.
  547. </p>
  548. </dd>
  549. <dt><code>A</code></dt>
  550. <dd><p>Like <code>a</code>, except uses <code>X</code>, <code>P</code>, and
  551. <code>ABCDEF</code> instead of lower case.
  552. </p>
  553. </dd>
  554. <dt><code>n</code></dt>
  555. <dd><p>Takes a pointer to <code>int</code>, and stores a count
  556. of the number of bytes written so far. No
  557. output is created.
  558. </p>
  559. </dd>
  560. <dt><code>p</code></dt>
  561. <dd><p>Takes a pointer to <code>void</code>, and prints it in
  562. an implementation-defined format. This
  563. implementation is similar to <code>%#tx</code>), except
  564. that <code>0x</code> appears even for the NULL pointer.
  565. </p>
  566. </dd>
  567. <dt><code>m</code></dt>
  568. <dd><p>Prints the output of <code>strerror(errno)</code>; no
  569. argument is required. A GNU extension.
  570. </p>
  571. </dd>
  572. </dl>
  573. </li></ul>
  574. <p><code>_wprintf_r</code>, <code>_fwprintf_r</code>, <code>_swprintf_r</code>, are simply
  575. reentrant versions of the functions above.
  576. </p>
  577. <br>
  578. <p><strong>Returns</strong><br>
  579. On success, <code>swprintf</code> return the number of wide characters in
  580. the output string, except the concluding <code>NUL</code> is not counted.
  581. <code>wprintf</code> and <code>fwprintf</code> return the number of characters transmitted.
  582. </p>
  583. <p>If an error occurs, the result of <code>wprintf</code>, <code>fwprintf</code>, and
  584. <code>swprintf</code> is a negative value. For <code>wprintf</code> and <code>fwprintf</code>,
  585. <code>errno</code> may be set according to <code>fputwc</code>. For <code>swprintf</code>, <code>errno</code>
  586. may be set to EOVERFLOW if <var>size</var> is greater than INT_MAX / sizeof (wchar_t),
  587. or when the output does not fit into <var>size</var> wide characters (including the
  588. terminating wide <code>NULL</code>).
  589. </p>
  590. <br>
  591. <p><strong>Bugs</strong><br>
  592. The &ldquo;&rdquo;&rsquo; (quote) flag does not work when locale&rsquo;s thousands_sep is not empty.
  593. </p>
  594. <br>
  595. <p><strong>Portability</strong><br>
  596. POSIX-1.2008 with extensions; C99 (compliant except for POSIX extensions).
  597. </p>
  598. <p>Depending on how newlib was configured, not all format specifiers are
  599. supported.
  600. </p>
  601. <p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
  602. <code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
  603. </p>
  604. <br>
  605. <hr>
  606. <div class="header">
  607. <p>
  608. Next: <a href="swscanf.html#swscanf" accesskey="n" rel="next">swscanf</a>, Previous: <a href="stdio_005fext.html#stdio_005fext" accesskey="p" rel="prev">stdio_ext</a>, Up: <a href="Stdio.html#Stdio" accesskey="u" rel="up">Stdio</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  609. </div>
  610. </body>
  611. </html>