printf.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <meta http-equiv="Content-Style-Type" content="text/css">
  6. <link rel="up" title="FatFs" href="../00index_e.html">
  7. <link rel="alternate" hreflang="ja" title="Japanese" href="../ja/printf.html">
  8. <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
  9. <title>FatFs - f_printf</title>
  10. </head>
  11. <body>
  12. <div class="para func">
  13. <h2>f_printf</h2>
  14. <p>The f_printf function writes formatted string to the file.</p>
  15. <pre>
  16. int f_printf (
  17. FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
  18. const TCHAR* <span class="arg">fmt</span>, <span class="c">/* [IN] Format stirng */</span>
  19. ...
  20. );
  21. </pre>
  22. </div>
  23. <div class="para arg">
  24. <h4>Parameters</h4>
  25. <dl class="par">
  26. <dt>fp</dt>
  27. <dd>Pointer to the open file object structure.</dd>
  28. <dt>fmt</dt>
  29. <dd>Pointer to the null terminated format string. The terminator charactor will not be written.</dd>
  30. <dt>...</dt>
  31. <dd>Optional arguments...</dd>
  32. </dl>
  33. </div>
  34. <div class="para ret">
  35. <h4>Return Values</h4>
  36. <p>When the function succeeded, it returns number of characters written. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
  37. </div>
  38. <div class="para desc">
  39. <h4>Description</h4>
  40. <p>The <tt>f_printf()</tt> is a wrapper function of <a href="write.html"><tt>f_write()</tt></a>. The format control directive is a sub-set of standard library shown as follos:</p>
  41. <ul>
  42. <li>Type: <tt>c C s S d D u U x X b B</tt></li>
  43. <li>Size: <tt>l L</tt></li>
  44. <li>Flag: <tt>0 -</tt></li>
  45. </ul>
  46. </div>
  47. <div class="para comp">
  48. <h4>QuickInfo</h4>
  49. <p>Available when <tt>_FS_READONLY == 0</tt> and <tt>_USE_STRFUNC</tt> is 1 or 2. When it is set to 2, <tt>'\n'</tt>s contained in the output are converted to <tt>'\r'+'\n'</tt>.</p>
  50. <p>When FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), data types on the srting fuctions, <tt>f_putc()</tt>, <tt>f_puts()</tt>, <tt>f_printf()</tt> and <tt>f_gets()</tt>, is also switched to Unicode. The character encoding on the file to be read/written via those functions is selected by <tt>_STRF_ENCODE</tt> option.</p>
  51. </div>
  52. <div class="para use">
  53. <h4>Example</h4>
  54. <pre>
  55. f_printf(&amp;fil, "%d", 1234); <span class="c">/* "1234" */</span>
  56. f_printf(&amp;fil, "%6d,%3d%%", -200, 5); <span class="c">/* " -200, 5%" */</span>
  57. f_printf(&amp;fil, "%ld", 12345L); <span class="c">/* "12345" */</span>
  58. f_printf(&amp;fil, "%06d", 25); <span class="c">/* "000025" */</span>
  59. f_printf(&amp;fil, "%06d", -25); <span class="c">/* "000-25" */</span>
  60. f_printf(&amp;fil, "%-6d", 25); <span class="c">/* "25 " */</span>
  61. f_printf(&amp;fil, "%u", -1); <span class="c">/* "65535" or "4294967295" */</span>
  62. f_printf(&amp;fil, "%04x", 0xAB3); <span class="c">/* "0ab3" */</span>
  63. f_printf(&amp;fil, "%08LX", 0x123ABCL); <span class="c">/* "00123ABC" */</span>
  64. f_printf(&amp;fil, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span>
  65. f_printf(&amp;fil, "%s", "String"); <span class="c">/* "String" */</span>
  66. f_printf(&amp;fil, "%8s", "abc"); <span class="c">/* " abc" */</span>
  67. f_printf(&amp;fil, "%-8s", "abc"); <span class="c">/* "abc " */</span>
  68. f_printf(&amp;fil, "%c", 'a'); <span class="c">/* "a" */</span>
  69. f_printf(&amp;fil, "%f", 10.0); <span class="c">/* f_printf lacks floating point support */</span>
  70. </pre>
  71. </div>
  72. <div class="para ref">
  73. <h4>See Also</h4>
  74. <p><tt><a href="open.html">f_open</a>, <a href="putc.html">f_putc</a>, <a href="puts.html">f_puts</a>, <a href="gets.html">f_gets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
  75. </div>
  76. <p class="foot"><a href="../00index_e.html">Return</a></p>
  77. </body>
  78. </html>