HP C/iX Library Reference Manual (30026-90004)
Chapter 5 271
HP C/iX Library Function Descriptions
printf
printf
Writes data in formatted form to the standard output stream stdout.
Syntax
#include <stdio.h>
int printf (const char *
format [,item [,item]...]
);
Parameters
format
A pointer to a character string defining the format (or the character string
itself enclosed in double quotes).
item
,… Each
item
is a variable or expression specifying the data to print.
Return Values
≥0 If successful, the number of characters written.
<0 An error occurred.
Description
The printf function enables you to output data in formatted form. In the printf function,
format
is a pointer to a character string (or the character string itself enclosed in double
quotes) that specifies the format and content of the data to be printed. Each
item
is a
variable or expression specifying the data to print.
The printf() format is similar to the scanf function. It is made up of conversion
specifications and literal characters. Literal characters are all characters that are not part
of a conversion specification. Literal characters are printed on stdout exactly as they
appear in the format.
Conversion Specifications
The following list shows the different components of a conversion specification in their
correct sequence:
1. A percent sign (%), which signals the beginning of a conversion specification; to output
a literal percent sign, you must type two percent signs (%%).
2. Zero or more flags, which affect the way a value is printed (see below).
3. An optional decimal digit string which specifies a minimum
field width
.
4. An optional
precision
consisting of a dot (.) followed by a decimal digit string.
5. An optional l, h, or L indicating that the argument is of an alternate type. When used
in conjunction with an integer conversion character, an l or h indicates a long or short
integer argument, respectively. When used in conjunction with a floating-point
conversion character, an L indicates a long double argument.