printf.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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* <em>FileObject</em>, <span class="c">/* File object */</span>
  18. const TCHAR* <em>Foramt</em>, <span class="c">/* Format stirng */</span>
  19. ...
  20. );
  21. </pre>
  22. </div>
  23. <div class="para arg">
  24. <h4>Parameters</h4>
  25. <dl class="par">
  26. <dt>FileObject</dt>
  27. <dd>Pointer to the open file object structure.</dd>
  28. <dt>Format</dt>
  29. <dd>Pointer to the null terminated format string.</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, number of characters written is returned. 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 f_printf() is a wrapper function of <a href="putc.html">f_putc()</a> and <a href="puts.html">f_puts()</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 the FatFs is configured to Unicode API (<tt>_LFN_UNICODE == 1</tt>), the generated UCS-2 characters are written to the file in UTF-8 encoding. If not the case, the byte characters will be written directly.</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, "%-6u", 100); <span class="c">/* "100 " */</span>
  58. f_printf(&amp;fil, "%ld", 12345678L); <span class="c">/* "12345678" */</span>
  59. f_printf(&amp;fil, "%04x", 0xA3); <span class="c">/* "00a3" */</span>
  60. f_printf(&amp;fil, "%08LX", 0x123ABC); <span class="c">/* "00123ABC" */</span>
  61. f_printf(&amp;fil, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span>
  62. f_printf(&amp;fil, "%s", "String"); <span class="c">/* "String" */</span>
  63. f_printf(&amp;fil, "%-4s", "abc"); <span class="c">/* "abc " */</span>
  64. f_printf(&amp;fil, "%4s", "abc"); <span class="c">/* " abc" */</span>
  65. f_printf(&amp;fil, "%c", 'a'); <span class="c">/* "a" */</span>
  66. f_printf(&amp;fil, "%f", 10.0); <span class="c">/* f_printf lacks floating point support */</span>
  67. </pre>
  68. </div>
  69. <div class="para ref">
  70. <h4>See Also</h4>
  71. <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>
  72. </div>
  73. <p class="foot"><a href="../00index_e.html">Return</a></p>
  74. </body>
  75. </html>