printf.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <html>
  2. <head>
  3. <title>printf</title>
  4. <body bgcolor=#ffffff>
  5. <h2 align=center>printf</h2>
  6. <h4 align=center>OS/161 Reference Manual</h4>
  7. <h3>Name</h3>
  8. printf - print formatted output
  9. <h3>Library</h3>
  10. Standard C Library (libc, -lc)
  11. <h3>Synopsis</h3>
  12. #include &lt;stdio.h&gt;<br>
  13. <br>
  14. int<br>
  15. printf(const char *<em>format</em>, ...);
  16. <h3>Description</h3>
  17. printf prints formatted text to standard output. The text is generated
  18. from the <em>format</em> argument and subsequent arguments according
  19. to the following rules.
  20. <p>
  21. Characters in <em>format</em> that are not the percent sign (`%') are
  22. printed verbatim. When a percent sign is encountered, the next
  23. argument of the arguments following <em>format</em> is retrieved and
  24. printed. The type of the argument expected, as well as some simple
  25. formatting instructions, are derived from the characters following the
  26. percent sign.
  27. <p>
  28. The following characters designate types to print. One of these
  29. characters concludes the format sequence begun with a percent sign,
  30. and also determines the type expected as an argument.
  31. <blockquote>
  32. <table width=90%>
  33. <tr><td width=5%>%</td> <td>A percent sign is printed; no argument
  34. is consumed.</td></tr>
  35. <tr><td>c</td> <td>Character (char, passed as int)</td></tr>
  36. <tr><td>d</td> <td>Signed integer printed in decimal</td></tr>
  37. <tr><td>o</td> <td>Unsigned integer printed in octal</td></tr>
  38. <tr><td>p</td> <td>Pointer (void *)</td></tr>
  39. <tr><td>s</td> <td>String (const char *)</td></tr>
  40. <tr><td>u</td> <td>Unsigned integer printed in decimal</td></tr>
  41. <tr><td>x</td> <td>Unsigned integer printed in hexadecimal</td></tr>
  42. <tr><td>X</td> <td>Unsigned integer printed in uppercase hex</td></tr>
  43. </table>
  44. </blockquote>
  45. The following characters are modifiers; they can be found between the
  46. percent sign and the type designator.
  47. <blockquote>
  48. <table width=90%>
  49. <tr><td width=5% valign=top>#</td> <td>Select an "alternate
  50. format". On integer formats this
  51. causes the C base prefix to be printed
  52. along with the integer. On other
  53. formats, this has no effect.</td></tr>
  54. <tr><td valign=top>l</td> <td>Assume an integer argument is long or
  55. unsigned long instead of int or
  56. unsigned int.</td></tr>
  57. <tr><td valign=top>0-9</td> <td>Digits are treated as a decimal number,
  58. which is considered to be the field
  59. width. The argument is printed
  60. right-aligned in a field that many
  61. characters wide.</td></tr>
  62. <tr><td valign=top>0</td> <td>If the field width has a leading 0, the
  63. padding character for alignment is
  64. made 0 (zero) instead of
  65. space.</td></tr>
  66. <tr><td valign=top>-</td> <td>If a field width is given, use it for
  67. left alignment instead of right
  68. alignment.</td></tr>
  69. </table>
  70. </blockquote>
  71. <h3>Restrictions</h3>
  72. Note that this is a limited printf implementation - it has no support
  73. for precisions (".number" as a modifier), floating-point formats,
  74. field widths passed as arguments, or the rarely-used `+' and ` '
  75. modifiers.
  76. <h3>Return Values</h3>
  77. printf returns the number of characters printed.
  78. </body>
  79. </html>