HP C/iX Library Reference Manual (30026-90004)
320 Chapter5
HP C/iX Library Function Descriptions
sprintf
e The float or double
item
is converted to scientific notation in style e;
that is, in the form
[-]d.ddde±ddd
where there is always one digit before the decimal point. The number of
digits after the decimal point is equal to the
precision
.Ifno
precision
is
given, six digits are written after the decimal point. If the
precision
is
explicitly zero, the decimal point is eliminated entirely. The exponent
always contains exactly three digits. If the # flag is specified, the result
always contains a decimal point, even if no digits follow the decimal point.
E Same as e above, except that E is used to introduce the exponent instead of
e (style E).
g The float or double
item
is converted to either style f or style e,
depending on the size of the exponent. If the exponent resulting from the
conversion is less than -4 or greater than the
precision
, style e is used.
Otherwise, style f is used. The
precision
specifies the number of
significant digits. Trailing zeros are removed from the result, and a
decimal point appears only if it is followed by a digit. If the # flag is
specified, the result always has a decimal point, even if no digits follow the
decimal point, and trailing zeros are not removed.
G Same as the g conversion above, except that style E is used instead of style
e.
Other conversion characters are:
p The argument is a pointer to void. The value of the pointer is converted to
a sequence of printable characters.
n The argument is a pointer to an integer into which is written the number
of characters written to the output stream so far by this call to fprintf().
No argument is converted.
% A % is written. No argument is converted. The complete conversion
specification is &%&%.
The
item
s in the item list may be variable names or expressions. Note that, with the
exception of the s conversion, pointers are not required in the item list. If the s conversion
is used, a pointer to a character string must be specified.
Example
The following program formats data. A user enters data and that data is reformatted into
a string, which is passed along to another program, such as a database maintainer. The
string contains the data that the user entered, but in a form using strict field widths for
the various pieces of data.
The database program might require these field widths to be processed correctly, and you
need not require the user to enter the data with the field widths. Users can enter data in a
convenient form without the fixed field restrictions imposed by the database.
#include <stdio.h>
main()