home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 110_01 / printf.c < prev    next >
C/C++ Source or Header  |  1984-03-03  |  1KB  |  48 lines

  1. /*
  2.     from STDLIB2.C for BDS C 1.41
  3.  
  4.  
  5.     This version of _spr adds the '0' padding option (see K&R, section
  6.     7.3) to the printf, etc. functions.
  7.     If a leading 0 is given in the field length for numeric conversions
  8.     the leading spaces are changed to leading 0s. Useful when two
  9.     numbers are to be concatenated for printing, e.g., split octal
  10.     notation: "017.002".
  11.     One side effect of this is that a right justified character or
  12.     string is also allowed to have leading 0s, but K&R's description
  13.     doesn't appear to disallow it, so...
  14. */
  15.  
  16. _spr(line,fmt)
  17. char *line, **fmt;
  18. {
  19.     char _uspr(), c, base, *sptr, *format;
  20.     char wbuf[MAXLINE], *wptr, pf, ljflag;
  21.  
  22. /*
  23.     the first modification: define a variable to hold the
  24.     padding character.
  25. */
  26.     char padchr;
  27.  
  28.     int width, precision,  *args;
  29.  
  30.     format = *fmt++;    /* fmt first points to the format string    */
  31.     args = fmt;        /* now fmt points to the first arg value    */
  32.  
  33.     while (c = *format++)
  34.       if (c == '%') {
  35.         wptr = wbuf;
  36.         precision = 6;
  37.         ljflag = pf = 0;
  38.  
  39.         if (*format == '-') {
  40.             format++;
  41.             ljflag++;
  42.          }
  43. /*
  44.     here's the additional logic: simply test if the character
  45.     following the '%' or '-' is a '0', and set padchr to
  46.     '0' if true, otherwise ' '.
  47. */
  48.         else if