home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdio / printf.txh < prev    next >
Encoding:
Text File  |  1996-05-20  |  3.2 KB  |  160 lines

  1. @node printf, stdio
  2. @subheading Syntax
  3.  
  4. @example
  5. #include <stdio.h>
  6.  
  7. int printf(const char *format, @dots{});
  8. @end example
  9.  
  10. @subheading Description
  11.  
  12. Sends formatted output from the arguments (@dots{}) to @code{stdout}.
  13.  
  14. The format string contains regular characters to print, as well as
  15. conversion specifiers, which begin with a percent symbol.  Each
  16. conversion speficier contains the following fields:
  17.  
  18. @itemize @bullet
  19.  
  20. @item
  21.  
  22. an optional flag, which may alter the conversion:
  23.  
  24. @table @code
  25.  
  26. @item -
  27.  
  28. left-justify the field.
  29.  
  30. @item +
  31.  
  32. Force a @code{+} sign on positive numbers.
  33.  
  34. @item space
  35.  
  36. To leave a blank space where a plus or minus sign would have been. 
  37.  
  38. @item #
  39.  
  40. Alternate conversion - prefix octal numbers with @code{0}, hexadecimal
  41. numbers with @code{0x} or @code{0X}, or force a trailing decimal point
  42. if a floating point conversion would have omitted it. 
  43.  
  44. @item 0
  45.  
  46. To pad numbers with leading zeros.
  47.  
  48. @end table
  49.  
  50. @item
  51.  
  52. A field width specifier, which specifies the minimum width of the field. 
  53. This may also be an asterisk (@code{*}), which means that the actual
  54. width will be obtained from the next argument.  If the argument is
  55. negative, it supplies a @code{-} flag and a positive width. 
  56.  
  57. @item
  58.  
  59. An optional decimal point and a precision.  This may also be an
  60. asterisk, but a negative argument for it indicates a precision of zero. 
  61. The precision specifies the minimum number of digits to print for an
  62. integer, the number of fraction digits for a floating point number (max
  63. for @code{g} or @code{G}, actual for others), or the maximum number of
  64. characters for a string. 
  65.  
  66. @item
  67.  
  68. An optional conversion qualifier, which may be @code{h} to specify
  69. @code{short}, @code{l} to specify long ints, or @code{L} to specify
  70. long doubles. Long long type can be specified by @code{L} or @code{ll}.
  71.  
  72. @item
  73.  
  74. The conversion type specifier:
  75.  
  76. @table @code
  77.  
  78. @item c
  79.  
  80. A single character
  81.  
  82. @item d
  83.  
  84. A signed integer
  85.  
  86. @item D
  87.  
  88. A signed long integer
  89.  
  90. @item e
  91. @itemx E
  92.  
  93. A floating point number (double or long double).  The exponent case matches
  94. the specifier case.  The representation always has an exponent.
  95.  
  96. @item f
  97.  
  98. A floating point number (double or long double).  The representation
  99. never has an exponent. 
  100.  
  101. @item g
  102. @itemx G
  103.  
  104. A floating point number (double or long double).  The exponent case matches
  105. the specifier case.  The representation has an exponent if it needs one.
  106.  
  107. @item i
  108.  
  109. A signed integer.
  110.  
  111. @item n
  112.  
  113. The next argument is a pointer to an integer, and the number of
  114. characters generated so far is stored in that integer. 
  115.  
  116. @item o
  117.  
  118. A unsigned integer, printed in base 8 instead of base 10.
  119.  
  120. @item p
  121.  
  122. A pointer.  This is printed with an @code{x} specifier.
  123.  
  124. @item s
  125.  
  126. A @code{NULL}-terminated string.
  127.  
  128. @item u
  129.  
  130. An unsigned integer.
  131.  
  132. @item U
  133.  
  134. An unsigned long integer.
  135.  
  136. @item x
  137. @itemx X
  138.  
  139. An unsigned integer, printed in base 16 instead of base 10.  The case of
  140. the letters used matches the specifier case. 
  141.  
  142. @item %
  143.  
  144. A single percent symbol is printed.
  145.  
  146. @end table
  147.  
  148. @end itemize
  149.  
  150. @subheading Return Value
  151.  
  152. The number of characters written.
  153.  
  154. @subheading Example
  155.  
  156. @example
  157. printf("%-3d %10.2f%% Percent of %s\n", index, per[index], name[index]);
  158. @end example
  159.  
  160.