summaryrefslogtreecommitdiff
path: root/usr/src/man/man3ucb/printf.3ucb
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/man/man3ucb/printf.3ucb')
-rw-r--r--usr/src/man/man3ucb/printf.3ucb373
1 files changed, 373 insertions, 0 deletions
diff --git a/usr/src/man/man3ucb/printf.3ucb b/usr/src/man/man3ucb/printf.3ucb
new file mode 100644
index 0000000000..cf104cdacc
--- /dev/null
+++ b/usr/src/man/man3ucb/printf.3ucb
@@ -0,0 +1,373 @@
+'\" te
+.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
+.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
+.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
+.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
+.TH printf 3UCB "30 Oct 2007" "SunOS 5.11" "SunOS/BSD Compatibility Library Functions"
+.SH NAME
+printf, fprintf, sprintf, vprintf, vfprintf, vsprintf \- formatted output
+conversion
+.SH SYNOPSIS
+.LP
+.nf
+\fB/usr/ucb/cc\fR [\fIflag\fR ...] \fIfile\fR ...
+#include <stdio.h>
+
+\fBint\fR \fBprintf\fR(\fIformat\fR, \fI\&...\fR)
+\fBconst char *\fR\fIformat\fR;
+.fi
+
+.LP
+.nf
+\fBint\fR \fBfprintf\fR(\fIstream\fR, \fIformat\fR, \fIva_list\fR)
+\fBFILE *\fR\fIstream\fR;
+\fBchar *\fR\fIformat\fR;
+\fIva_dcl\fR;
+.fi
+
+.LP
+.nf
+\fBchar *\fR\fBsprintf\fR(\fIs\fR, \fIformat\fR, \fIva_list\fR)
+\fBchar *\fR\fIs\fR, \fB*\fR\fIformat\fR;
+\fIva_dcl\fR;
+.fi
+
+.LP
+.nf
+\fBint\fR \fBvprintf\fR(\fIformat\fR, \fIap\fR)
+\fBchar *\fR\fIformat\fR;
+\fBva_list\fR \fIap\fR;
+.fi
+
+.LP
+.nf
+\fBint\fR \fBvfprintf\fR(\fIstream\fR, \fIformat\fR, \fIap\fR)
+\fBFILE *\fR\fIstream\fR;
+\fBchar *\fR\fIformat\fR;
+\fBva_list\fR \fIap\fR;
+.fi
+
+.LP
+.nf
+\fBchar *\fR\fBvsprintf\fR(\fIs\fR, \fIformat\fR, \fIap\fR)
+\fBchar *\fR\fIs\fR, \fB*\fR\fIformat\fR;
+\fBva_list\fR \fIap\fR;
+.fi
+
+.SH DESCRIPTION
+.sp
+.LP
+\fBprintf()\fR places output on the standard output stream \fBstdout\fR.
+\fBfprintf()\fR places output on the named output \fIstream\fR. \fBsprintf()\fR
+places "output," followed by the \fINULL\fR character (\fB\e0\fR), in
+consecutive bytes starting at *\fIs\fR; it is the user's responsibility to
+ensure that enough storage is available.
+.sp
+.LP
+\fBvprintf()\fR, \fBvfprintf()\fR, and \fBvsprintf()\fR are the same as
+\fBprintf()\fR, \fBfprintf()\fR, and \fBsprintf()\fR respectively, except that
+instead of being called with a variable number of arguments, they are called
+with an argument list as defined by \fB<varargs.h>\fR.
+.sp
+.LP
+Each of these functions converts, formats, and prints its \fIarg\fRs under
+control of the \fIformat\fR. The \fIformat\fR is a character string which
+contains two types of objects: plain characters, which are simply copied to the
+output stream, and conversion specifications, each of which causes conversion
+and printing of zero or more \fIarg\fRs. The results are undefined if there are
+insufficient \fIarg\fRs for the format. If the format is exhausted while
+\fIarg\fRs remain, the excess \fIarg\fRs are simply ignored.
+.sp
+.LP
+Each conversion specification is introduced by the character \fB%\fR. After the
+\fB%\fR, the following appear in sequence:
+.RS +4
+.TP
+.ie t \(bu
+.el o
+Zero or more \fIflags\fR, which modify the meaning of the conversion
+specification.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+An optional decimal digit string specifying a minimum \fIfield width\fR. If the
+converted value has fewer characters than the field width, it will be padded on
+the left (or right, if the left-adjustment flag `\fB\(mi\fR\&', described
+below, has been given) to the field width. The padding is with blanks unless
+the field width digit string starts with a zero, in which case the padding is
+with zeros.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+A \fIprecision\fR that gives the minimum number of digits to appear for the
+\fBd\fR, \fBi\fR, \fBo\fR, \fBu\fR, \fBx\fR, or \fBX\fR conversions, the number
+of digits to appear after the decimal point for the \fBe\fR, \fBE\fR, and
+\fBf\fR conversions, the maximum number of significant digits for the \fBg\fR
+and \fBG\fR conversion, or the maximum number of characters to be printed from
+a string in \fBs\fR conversion. The precision takes the form of a period
+(\fB\&.\fR) followed by a decimal digit string; a \fINULL\fR digit string is
+treated as zero. Padding specified by the precision overrides the padding
+specified by the field width.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+An optional \fBl\fR (ell) specifying that a following \fBd\fR, \fBi\fR,
+\fBo\fR, \fBu\fR, \fBx\fR, or \fBX\fR conversion character applies to a long
+integer \fIarg\fR. An \fBl\fR before any other conversion character is ignored.
+.RE
+.RS +4
+.TP
+.ie t \(bu
+.el o
+A character that indicates the type of conversion to be applied.
+.RE
+.sp
+.LP
+A field width or precision or both may be indicated by an asterisk (\fB*\fR)
+instead of a digit string. In this case, an integer \fIarg\fR supplies the
+field width or precision. The \fIarg\fR that is actually converted is not
+fetched until the conversion letter is seen, so the \fIarg\fRs specifying field
+width or precision must appear \fIbefore\fR the \fIarg\fR (if any) to be
+converted. A negative field width argument is taken as a `\fB\(mi\fR\&' flag
+followed by a positive field width. If the precision argument is negative, it
+will be changed to zero.
+.sp
+.LP
+The flag characters and their meanings are:
+.sp
+.ne 2
+.mk
+.na
+\fB\fB\(mi\fR\fR
+.ad
+.RS 9n
+.rt
+The result of the conversion will be left-justified within the field.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fB+\fR\fR
+.ad
+.RS 9n
+.rt
+The result of a signed conversion will always begin with a sign (\fB+\fR or
+\fB\(mi\fR).
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fBblank\fR
+.ad
+.RS 9n
+.rt
+If the first character of a signed conversion is not a sign, a blank will be
+prefixed to the result. This implies that if the blank and \fB+\fR flags both
+appear, the blank flag will be ignored.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fB#\fR\fR
+.ad
+.RS 9n
+.rt
+This flag specifies that the value is to be converted to an "alternate form."
+For \fBc\fR, \fBd\fR, \fBi\fR, \fBs\fR, and \fBu\fR conversions, the flag has
+no effect. For \fBo\fR conversion, it increases the precision to force the
+first digit of the result to be a zero. For \fBx\fR or \fBX\fR conversion, a
+non-zero result will have \fB0x\fR or \fB0X\fR prefixed to it. For \fBe\fR,
+\fBE\fR, \fBf\fR, \fBg\fR, and \fBG\fR conversions, the result will always
+contain a decimal point, even if no digits follow the point (normally, a
+decimal point appears in the result of these conversions only if a digit
+follows it). For \fBg\fR and \fBG\fR conversions, trailing zeroes will
+\fInot\fR be removed from the result (which they normally are).
+.RE
+
+.sp
+.LP
+The conversion characters and their meanings are:
+.sp
+.ne 2
+.mk
+.na
+\fB\fBd\fR,\fBi\fR,\fBo\fR,\fBu\fR,\fBx\fR,\fBX\fR\fR
+.ad
+.RS 15n
+.rt
+The integer \fIarg\fR is converted to signed decimal (\fBd\fR or \fBi\fR),
+unsigned octal (\fBo\fR), unsigned decimal (\fBu\fR), or unsigned hexadecimal
+notation (\fBx\fR and \fBX\fR), respectively; the letters \fBabcdef\fR are used
+for \fBx\fR conversion and the letters \fBABCDEF\fR for \fBX\fR conversion. The
+precision specifies the minimum number of digits to appear; if the value being
+converted can be represented in fewer digits, it will be expanded with leading
+zeroes. (For compatibility with older versions, padding with leading zeroes may
+alternatively be specified by prepending a zero to the field width. This does
+not imply an octal value for the field width.) The default precision is 1. The
+result of converting a zero value with a precision of zero is a \fINULL\fR
+string.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fBf\fR\fR
+.ad
+.RS 15n
+.rt
+The float or double \fIarg\fR is converted to decimal notation in the style
+[\fB\(mi\fR]\fIddd\fR\fB\&.\fR\fIddd\fR where the number of digits after the
+decimal point is equal to the precision specification. If the precision is
+missing, 6 digits are given; if the precision is explicitly 0, no digits and no
+decimal point are printed.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fBe\fR,\fBE\fR\fR
+.ad
+.RS 15n
+.rt
+The float or double \fIarg\fR is converted in the style
+[\fB\(mi\fR]\fId\fR\fB\&.\fR\fIddd\fR\fBe\(+-\fR\fIddd\fR, where there is one
+digit before the decimal point and the number of digits after it is equal to
+the precision; when the precision is missing, 6 digits are produced; if the
+precision is zero, no decimal point appears. The \fBE\fR format code will
+produce a number with \fBE\fR instead of \fBe\fR introducing the exponent. The
+exponent always contains at least two digits.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fBg\fR,\fBG\fR\fR
+.ad
+.RS 15n
+.rt
+The float or double \fIarg\fR is printed in style \fBf\fR or \fBe\fR (or in
+style \fBE\fR in the case of a \fBG\fR format code), with the precision
+specifying the number of significant digits. The style used depends on the
+value converted: style \fBe\fR or \fBE\fR will be used only if the exponent
+resulting from the conversion is less than \(mi4 or greater than the precision.
+Trailing zeroes are removed from the result; a decimal point appears only if it
+is followed by a digit.
+.RE
+
+.sp
+.LP
+The \fBe\fR, \fBE f\fR, \fBg,\fR and \fBG\fR formats print \fBIEEE\fR
+indeterminate values (infinity or not-a-number) as "Infinity" or "NaN"
+respectively.
+.sp
+.ne 2
+.mk
+.na
+\fB\fBc\fR\fR
+.ad
+.RS 5n
+.rt
+The character \fIarg\fR is printed.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fBs\fR\fR
+.ad
+.RS 5n
+.rt
+The \fIarg\fR is taken to be a string (character pointer) and characters from
+the string are printed until a \fINULL\fR character (\fB\e0\fR) is encountered
+or until the number of characters indicated by the precision specification is
+reached. If the precision is missing, it is taken to be infinite, so all
+characters up to the first \fINULL\fR character are printed. A \fINULL\fR value
+for \fIarg\fR will yield undefined results.
+.RE
+
+.sp
+.ne 2
+.mk
+.na
+\fB\fB%\fR\fR
+.ad
+.RS 5n
+.rt
+Print a \fB%\fR; no argument is converted.
+.RE
+
+.sp
+.LP
+In no case does a nonexistent or small field width cause truncation of a field;
+if the result of a conversion is wider than the field width, the field is
+simply expanded to contain the conversion result. Padding takes place only if
+the specified field width exceeds the actual width. Characters generated by
+\fBprintf()\fR and \fBfprintf()\fR are printed as if \fBputc\fR(3C) had been
+called.
+.SH RETURN VALUES
+.sp
+.LP
+Upon success, \fBprintf()\fR and \fBfprintf()\fR return the number of
+characters transmitted, excluding the null character. \fBvprintf()\fR and
+\fBvfprintf()\fR return the number of characters transmitted. \fBsprintf()\fR
+and \fBvsprintf()\fR always return \fIs\fR. If an output error is encountered,
+\fBprintf()\fR, \fBfprint()\fR, \fBvprintf()\fR, and \fBvfprintf()\fR return
+EOF.
+.SH EXAMPLES
+.LP
+\fBExample 1 \fRExamples of the \fBprintf\fR Command To Print a Date and Time
+.sp
+.LP
+To print a date and time in the form "Sunday, July 3, 10:02," where
+\fIweekday\fR and \fImonth\fR are pointers to \fINULL\fR-terminated strings:
+
+.sp
+.in +2
+.nf
+printf("%s, %s %i, %d:%.2d", weekday, month, day, hour, min);
+.fi
+.in -2
+
+.LP
+\fBExample 2 \fRExamples of the \fBprintf\fR Command To Print to Five Decimal
+Places
+.sp
+.LP
+To print to five decimal places:
+
+.sp
+.in +2
+.nf
+printf("pi \|= \|%.5f", \|4 * atan(1. 0));
+.fi
+.in -2
+
+.SH SEE ALSO
+.sp
+.LP
+\fBeconvert\fR(3C), \fBputc\fR(3C), \fBscanf\fR(3C), \fBvprintf\fR(3C)
+.SH NOTES
+.sp
+.LP
+Use of these interfaces should be restricted to only applications written on
+BSD platforms. Use of these interfaces with any of the system libraries or in
+multi-thread applications is unsupported.
+.sp
+.LP
+Very wide fields (>128 characters) fail.