|
|
coherent
printf() STDIO printf()
Print formatted text
iinntt pprriinnttff(_f_o_r_m_a_t [,_a_r_g_1, .... _a_r_g_N])
cchhaarr *_f_o_r_m_a_t; [ddaattaa ttyyppee] _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:
11. A minus sign `-' left-justifies the output field, instead of
the default right justify.
22. 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.
33. A period `.' followed by one or more digits gives the preci-
sion. For floating point (ee, ff, and gg) conversions, the
precision sets the number of digits printed after the decimal
point. For string (ss) 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.
44. The letter `ll' before any integer conversion (dd, oo, xx, or uu)
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.
cc Print the int argument as a character.
COHERENT Lexicon Page 1
printf() STDIO printf()
dd Print the int argument as signed decimal numerals.
DD Print the long argument as signed decimal numerals.
ee Print the float or double argument in exponential form. The
format is _d._d_d_d_d_d_dee_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 `-'.
ff 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).
gg Print the float or double argument as whichever of the formats
d, e, or f loses no significant precision and takes the least
space.
oo Print the int argument in unsigned octal numerals.
OO Print the long argument in unsigned octal numerals.
rr The next argument points to an array of new arguments that may
be used recursively. The first argument of the list is a cchhaarr
* 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.
ss Print the string to which the cchhaarr * 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.
uu Print the int argument in unsigned decimal numerals.
UU Print the long argument in unsigned decimal numerals.
xx Print the int argument in unsigned hexadecimal numerals.
XX Print the long argument in unsigned hexadecimal numerals.
***** Example *****
The following example demonstrates many pprriinnttff 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 lloonngg.
At present, pprriinnttff does not return a meaningful value.
COHERENT Lexicon Page 3
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.