HP C/iX Library Reference Manual (30026-90004)
Chapter 5 319
HP C/iX Library Function Descriptions
sprintf
Conversion Characters
Conversion characters specify the type of data to expect in the item list and cause the data
to be formatted and written appropriately. The integer conversion characters are:
d, i An integer
item
is converted to signed decimal. The
precision
, if given,
specifies the minimum number of digits to appear. If the value has fewer
digits than that specified by the
precision
, the value is expanded with
leading zeros. The default
precision
is 1. A null string results if a zero
value is written with a zero
precision
. The # flag has no effect.
u An integer
item
is converted to unsigned decimal. The effects of the
precision
and the # flag are the same as for d.
o An integer
item
is converted to unsigned octal. The # flag, if specified,
causes the
precision
to be expanded, and the octal value is written with a
leading zero (a C convention). The
precision
behaves the same as in d
above, except that writing a zero value with a zero
precision
results in
only the leading zero being written, if the # flag is specified.
x An integer
item
is converted to hexadecimal. The letters abcdef are used
in writing hexadecimal values. The # flag, if specified, causes the
precision
to be expanded, and the hexadecimal value is written with a
leading "0x" (a C convention). The
precision
behaves as in d above,
except that writing a zero value with a zero
precision
results in only the
leading "0x" being written, if the # flag is specified.
X Same as x above, except that the letters ABCDEF are used to write the
hexadecimal value, and the # flag causes the value to be written with a
leading "0X".
The character conversion characters are as follows:
c The character specified by the char
item
is written. The
precision
is
meaningless, and the # flag has no effect.
s The string pointed to by the character pointer
item
is written. If a
precision
is specified, characters from the string are written until the
number of characters indicated by the
precision
is reached, or until a
null character is encountered, whichever comes first. If the
precision
is
omitted, all characters up to the first null character are written. The # flag
has no effect.
The floating-point conversion characters are:
f The float or double
item
is converted to decimal notation in style f; that
is, in the form
[-]ddd.ddd
where the number of digits after the decimal point is equal to the
precision
. If no
precision
is specified, six digits are written after the
decimal point. If the
precision
is explicitly zero, the decimal point is
eliminated entirely. If the # flag is specified, a decimal point always
appears, even if no digits follow the decimal point.