home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 329_01 / synopsis.doc < prev    next >
Text File  |  1979-12-31  |  4KB  |  74 lines

  1. dprintf Synopsis
  2. (C) February 4  1990  Asaf Arkin
  3. All rights reserved
  4.  
  5.  
  6. The definitions below are necessary in order to use dprintf:
  7.  
  8. typedef  int (*dprintf_fp)(int);
  9.  
  10.  
  11. int  dprintf(OutFunc, Format, ...);
  12.      dprintf_fp   OutFunc;
  13.      const char  *Format;
  14.  
  15.  
  16. int  vdprintf(OutFunc, Format, Args);
  17.      dprintf_fp   OutFunc;
  18.      const char  *Format;
  19.      va_list      Args;
  20.  
  21. dprintf and vdprintf return the number of characters successfully printed, or EOF if an error of any sort occured.
  22.  
  23.  
  24. The complete format specification is (brackets enclose optional parameters):
  25.  
  26. %[Flags][Width][.[Precision]][Size]Format
  27.  
  28.  
  29. Flags is a list of zero or more from the following flags:
  30.  
  31. Flag   Explanation
  32.  -     Left justify prefix and value within field (cancels flag 0)
  33.  +     Positive numerical values are prefixed with a plus sign
  34.  spc   Positive numerical values are prefixed with a space (or a plus)
  35.  0     Insert zeros between prefix and numerical value
  36.  #     Print value in variant format
  37.  
  38.  
  39. Width and Precision parameters conform to these rules:
  40. -  Width must not start with a zero, which will be considered a flag; If absent, a zero width is assumed.
  41. -  If Precision is specified, it must precede with a period.
  42. -  If a period but no Precision appear, zero is assumed, which is different than omitting both period and precision value.
  43. -  If an * replaces either Width or Precision, an int is consumed from the variable arguments list for the parameter's value.
  44.  
  45.  
  46.  
  47. The output of most formats consists of prefix and value. Combined, if they are shorter than Width, they will be justified within their field: by default spaces precede prefix and value to right justify them; if the 0 flag appears, zeros are inserted between prefix and value; if the - flag appears (regardless of 0 flag), spaces follow value to left justify it.
  48.  
  49. For integers, Precision is the minimum number of digits used (one assumed, if absent); for floating points, Precision is the number of digits to follow the decimal point (6 assumed, if absent); for strings, Precision is the maximum number of characters printed.
  50.  
  51.  
  52. If the format is %d, %i, %u, %o or %x, the argument consumed is either int, short (size h) or long (size l); if the format is %e, %f or %g, the argument consumed is either double or long double (size L). The short size has no actual meaning, short arguments being promoted to int, and float arguments to double by the compiler.
  53.  
  54.  
  55. Format is a single letter and can be any one of the following:
  56.  
  57. Format  Argument Type     Resulting output
  58. c       unsigned char     A single character
  59. d       (long) int        Decimal integer with or without sign
  60. e / E   (long) double     Floating point number in engineering format
  61. f       (long) double     Floating point number in standard format
  62. g / G   (long) double     Floating point number in the shortest format of the two. Trailing zeros in the fraction are lost, unless in the variant format.
  63. i       (long) int        Decimal integer with or without sign
  64. n       int *             This is not an output format. Rather the number of characters printed so far is stored in the int, whose pointer is consumed.
  65. o       (long) unsigned   Unsigned integer in octal radix (variant format prefixes 0)
  66. p       void *            A pointer in implementation-defined format
  67. s       char *            A character string
  68. u       (long) unsigned   Unsigned integer in decimal radix
  69. x / X   (long) unsigned   Unsigned integer in hexadecimal radix (variant format prefixes 0x)
  70. %       ---               A percent sign
  71.  
  72. Hexadecimal letters are in the same case as is the format letter (%x or %X). So is the exponent's e of the %e/%E and %g/%G formats. All other formats are specified in lower case only.
  73.  
  74.