

printf()                      STDIO                      printf()




Print formatted text

iinntt pprriinnttff(_f_o_r_m_a_t [,_a_r_g_1, .... _a_r_g_N])
cchhaarr *_f_o_r_m_a_t; [ddaattaa ttyyppee] _a_r_g_1, ... _a_r_g_N;

printf  prints formatted  text.   It uses  the  format string  to
specify an  output format for  each arg, which it  then writes on
the standard output.

printf reads characters from  format one at a time; any character
other than a percent sign `%' or a string that is introduced with
a percent  sign is  copied directly to  the output.  A  `%' tells
printf that  what follows specifies how  the corresponding arg is
to be formatted; the characters  that follow `%' can set the out-
put  width and  the type  of  conversion desired.   The following
modifiers, in this order, may precede the conversion type:

11. A minus sign  `-'  left-justifies the output field, instead of
   the default right justify.

22. A string of digits gives the width of the output field.  Norm-
   ally, printf  pads the  fiel padded  with spaces to  the field
   width; it  is padded on the left  unless left justification is
   specified with a `-'.  If the field width begins with `0', the
   field is padded with `0' characters instead of spaces; the `0'
   does not cause the field width to be taken as an octal number.
   If  the width  specification is an  asterisk `*',  the routine
   uses the  next arg as an  integer that gives the  width of the
   field.

33. A period  `.' followed by one or more  digits gives the preci-
   sion.   For floating  point  (ee, ff,  and  gg) conversions,  the
   precision sets the  number of digits printed after the decimal
   point.   For string  (ss) conversions,  the precision  sets the
   maximum number of characters that can be used from the string.
   If the  precision specification is  given as an  asterisk `*',
   the routine  uses the  next arg as  an integer that  gives the
   precision.

44. The letter  `ll' before any integer conversion (dd,  oo, xx, or uu)
   indicates  that the  argument is  a long  rather than  an int.
   Capitalizing the  conversion type  has the same  effect; note,
   however, that capitalized  conversion types are not compatible
   with  all C  compiler libraries,  or  with the  ANSI standard.
   This  feature will  not  be supported  in  future editions  of
   COHERENT.

The following format conversions are recognized:

%  Print a `%' character.  No arguments are processed.

cc  Print the int argument as a character.




COHERENT Lexicon                                           Page 1




printf()                      STDIO                      printf()



dd  Print the int argument as signed decimal numerals.

DD  Print the long argument as signed decimal numerals.

ee  Print  the float or double argument  in exponential form.  The
   format is _d._d_d_d_d_d_dee_s_d_d, where there is always one digit before
   the decimal point and as many as the precision digits after it
   (default, six).  The exponent sign _s may be either `+' or `-'.

ff   Print  the float  or  double  argument as  a  string with  an
   optional leading minus  sign `-',  at least one decimal digit,
   a decimal  point (`.'), and optional  decimal digits after the
   decimal point.   The number of digits  after the decimal point
   is the precision (default, six).

gg  Print the float or double argument as whichever of the formats
   d, e, or f loses  no significant precision and takes the least
   space.

oo  Print the int argument in unsigned octal numerals.

OO  Print the long argument in unsigned octal numerals.

rr  The next argument points to an array of new arguments that may
   be used recursively.  The first argument of the list is a cchhaarr
   * that  contains a  new format string.   When the list  is ex-
   hausted, the  routine continues from where it  left off in the
   original format string.

ss   Print  the  string  to  which  the cchhaarr  *  argument  points.
   Reaching either  the end  of the  string, indicated by  a null
   character, or the  specified precision, will terminate output.
   If no precision is given, only the end of the string will ter-
   minate.

uu  Print the int argument in unsigned decimal numerals.

UU  Print the long argument in unsigned decimal numerals.

xx  Print the int argument in unsigned hexadecimal numerals.

XX  Print the long argument in unsigned hexadecimal numerals.

***** Example *****

The following example demonstrates many pprriinnttff statements.


main()
{
        extern void demo_r();
        int precision = 1;
        int integer = 10;
        float decimal = 2.75;
        double bigdec = 27590.21;


COHERENT Lexicon                                           Page 2




printf()                      STDIO                      printf()



        char letter = 'K';
        char buffer[20];



        strcpy (buffer, "This is a string.\n");



        printf("This is an int:   %d\n", integer);
        printf("This is a float:  %f\n", decimal);
        printf("Another float:    %3.*f\n", precision, decimal);
        printf("This is a double: %lf\n", bigdec);
        printf("This is a char:   %c\n", letter);
        printf("%s", buffer);
        printf("%s\n", "This is also a string.");



        demo_r("Print everything: %d %f %lf %c",
                integer, decimal, bigdec, letter);
        exit(0);
}



void demo_r(string)
char *string;
{
        printf("%r\n", (char **)&string);
}


***** See Also *****

fprintf(), putc(), puts(), scanf(), sprintf(), STDIO

***** Notes *****

Because C  does not perform  type checking, it  is essential that
each argument match its counterpart in the format string.

The use of upper-case format characters to specify long arguments
is not standard, and will be  phased out to conform with the ANSI
standard.  You should use the `l' modifier to indicate a lloonngg.

At present, pprriinnttff does not return a meaningful value.










COHERENT Lexicon                                           Page 3


