diff options
| author | Krónos <Krónos@Sāturnus> | 1993-10-11 00:00:00 +0100 |
|---|---|---|
| committer | Alejandro Colomar <alx@kernel.org> | 2022-12-15 23:09:38 +0100 |
| commit | 9e0fdb0c0192079e5847f49832374ea28b5ad436 (patch) | |
| tree | 0eb6ca406983d655aa04225550ec9f8a6c265e90 /man3/printf.3 | |
| parent | 3c23040573650f36a3f2778a3629f4ae7e6c10ab (diff) | |
| download | man-pages-prehistory-backwards.tar.gz | |
man-pages 1.0prehistory-backwards
man-pages-1.1 seems to be missing. :/
Link: <https://www.win.tue.nl/~aeb/ftpdocs/linux-local/manpages.archive/>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'man3/printf.3')
| -rw-r--r-- | man3/printf.3 | 507 |
1 files changed, 0 insertions, 507 deletions
diff --git a/man3/printf.3 b/man3/printf.3 deleted file mode 100644 index 5f347822f6..0000000000 --- a/man3/printf.3 +++ /dev/null @@ -1,507 +0,0 @@ -.\" Copyright (c) 1990, 1991 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)printf.3 6.14 (Berkeley) 7/30/91 -.\" -.\" Converted for Linux, Mon Nov 29 12:06:07 1993, faith@cs.unc.edu -.\" -.TH PRINTF 3 "29 November 1993" "BSD MANPAGE" "Linux Programmer's Manual" -.SH NAME -printf, fprintf, sprintf, vprintf, vfprintf, vsprintf \- formatted output conversion -.SH SYNOPSIS -.B #include <stdio.h> -.sp -.BI "int printf( const char *" format ", ...);" -.br -.BI "int fprintf( FILE *" stream ", const char *" format ", ...);" -.br -.BI "int sprintf( char *" str ", const char *" format ", ...);" -.sp -.B #include <stdarg.h> -.sp -.BI "int vprintf( const char *" format ", va_list " ap ); -.br -.BI "int vfprintf( FILE *" stream ", const char *" format ", va_list " ap ); -.br -.BI "int vsprintf( char *" str ", char *" format ", va_list " ap ); -.SH DESCRIPTION -The -.B printf -family of functions produces output according to a -.I format -as described below. -.B Printf -and -.B vprintf -write output to -.IR stdout , -the standard output stream; -.B fprintf -and -.B vfprintf -write output to the given output -.IR stream ; -.BR sprintf , -and -.BR vsprintf -write to the character string -.IR str . -These functions write the output under the control of a -.I format -string that specifies how subsequent arguments (or arguments accessed via -the variable-length argument facilities of -.BR stdarg (3) -are converted for output. These functions return the number of characters -printed (not including the trailing `\e0' used to end output to strings). -.PP -The format string is composed of zero or more directives: ordinary -characters (not -.BR % ), -which are copied unchanged to the output stream; -and conversion specifications, each of which results in fetching zero or -more subsequent arguments. Each conversion specification is introduced by -the character -.BR % . -The arguments must correspond properly (after type promotion) with the -conversion specifier. After the -.BR % , -the following appear in sequence: -.TP -.B \(bu -Zero or more of the following flags: -.RS -.TP -.B # -specifying that the value should be converted to an ``alternate form''. -For -.BR c , -.BR d , -.BR i , -.BR n , -.BR p , -.BR s , -and -.BR u -conversions, this option has no effect. For -.BR o -conversions, the precision of the number is increased to force the first -character of the output string to a zero (except if a zero value is printed -with an explicit precision of zero). -For -.B x -and -.B X -conversions, a non-zero result has the string `0x' (or `0X' for -.B X -conversions) prepended to it. For -.BR e , -.BR E , -.BR f , -.BR g , -and -.B G -conversions, the result will always contain a decimal point, even if no -digits follow it (normally, a decimal point appears in the results of those -conversions only if a digit follows). For -.B g -and -.B G -conversions, trailing zeros are not removed from the result as they would -otherwise be. -.TP -.B \&0 -specifying zero padding. For all conversions except -.BR n , -the converted value is padded on the left with zeros rather than blanks. -If a precision is given with a numeric conversion -.BR "" ( d , -.BR i , -.BR o , -.BR u , -.BR i , -.BR x , -and -.BR X ), -the -.B \&0 -flag is ignored. -.TP -.B \- -(a negative field width flag) indicates the converted value is to be left -adjusted on the field boundary. Except for -.B n -conversions, the converted value is padded on the right with blanks, rather -than on the left with blanks or zeros. A -.B \- -overrides a -.B \&0 -if both are given. -.TP -.B "" -(a space) specifying that a blank should be left before a positive number -produced by a signed conversion -.BR "" ( d , -.BR e , -.BR E , -.BR f , -.BR g , -.BR G , -or -.BR i ). -.TP -.B + -specifying that a sign always be placed before a number produced by a -signed conversion. A -.B + -overrides a space if both are used. -.RE -.TP -.B \(bu -An optional decimal digit string specifying a minimum field width. If the -converted value has fewer characters than the field width, it will be -padded with spaces on the left (or right, if the left-adjustment flag has -been given) to fill out the field width. -.TP -.B \(bu -An optional precision, in the form of a period (`\&.') followed by an -optional digit string. If the digit string is omitted, the precision is -taken as zero. This gives the minimum number of digits to appear for -.BR d , -.BR i , -.BR o , -.BR u , -.BR x , -and -.B X -conversions, the number of digits to appear after the decimal-point for -.BR e , -.BR E , -and -.B f -conversions, the maximum number of significant digits for -.B g -and -.B G -conversions, or the maximum number of characters to be printed from a -string for -.B s -conversions. -.TP -.B \(bu -The optional character -.BR h , -specifying that a following -.BR d , -.BR i , -.BR o , -.BR u , -.BR x , -or -.BR X -conversion corresponds to a -.I short int -or -.I unsigned short int -argument, or that a following -.B n -conversion corresponds to a pointer to a -.I short int -argument. -.TP -.B \(bu -The optional character -.B l -(ell) specifying that a following -.BR d , -.BR i , -.BR o , -.BR u , -.BR x , -or -.BR X -conversion applies to a pointer to a -.I long int -or -.I unsigned long int -argument, or that a following -.B n -conversion corresponds to a pointer to a -.I long int -argument. -.TP -.B \(bu -The character -.BR L -specifying that a following -.BR e , -.BR E , -.BR f , -.BR g , -or -.B G -conversion corresponds to a -.I long double -argument. -.TP -.B \(bu -A character that specifies the type of conversion to be applied. -.PP -A field width or precision, or both, may be indicated by an asterisk `*' -instead of a digit string. In this case, an -.I int -argument supplies the field width or precision. A negative field width is -treated as a left adjustment flag followed by a positive field width; a -negative precision is treated as though it were missing. -.PP -The conversion specifiers and their meanings are: -.TP -.B diouxX -The -.I int -(or appropriate variant) argument is converted to signed decimal -.BR "" ( d -and -.BR i ), -unsigned octal -.BR "" ( o , -unsigned decimal -.BR "" ( u , -or unsigned hexadecimal -.BR "" ( x -and -.BR X ) -notation. The letters -.B abcdef -are used for -.B x -conversions; the letters -.B ABCDEF -are used for -.B X -conversions. The precision, if any, gives the minimum number of digits -that must appear; if the converted value requires fewer digits, it is -padded on the left with zeros. -.TP -.B DOU -The -.I long int -argument is converted to signed decimal, unsigned octal, or unsigned -decimal, as if the format had been -.BR ld , -.BR lo , -or -.B lu -respectively. These conversion characters are deprecated, and will -eventually disappear. -.TP -.B eE -The -.I double -argument is rounded and converted in the style -.BR "" [\-]d \&. ddd e \\*(Pmdd -where there is one digit before the decimal-point character and the number -of digits after it is equal to the precision; if the precision is missing, -it is taken as 6; if the precision is zero, no decimal-point character -appears. An -.B E -conversion uses the letter -.B E -(rather than -.BR e ) -to introduce the exponent. The exponent always contains at least two -digits; if the value is zero, the exponent is 00. -.TP -.B f -The -.I double -argument is rounded and converted to decimal notation in the style -.BR "" [-]ddd \&. ddd, -where the number of digits after the decimal-point character is equal to -the precision specification. If the precision is missing, it is taken as -6; if the precision is explicitly zero, no decimal-point character appears. -If a decimal point appears, at least one digit appears before it. -.TP -.B g -The -.I double -argument is converted in style -.B f -or -.B e -(or -.B E -for -.B G -conversions). The precision specifies the number of significant digits. -If the precision is missing, 6 digits are given; if the precision is zero, -it is treated as 1. Style -.B e -is used if the exponent from its conversion is less than \-4 or greater -than or equal to the precision. Trailing zeros are removed from the -fractional part of the result; a decimal point appears only if it is -followed by at least one digit. -.TP -.B c -The -.I int -argument is converted to an -.IR unsigned char , -and the resulting character is written. -.TP -.B s -The -.IR "" `` "char *" '' -argument is expected to be a pointer to an array of character type (pointer -to a string). Characters from the array are written up to (but not -including) a terminating -.B NUL -character; if a precision is specified, no more than the number specified -are written. If a precision is given, no null character need be present; -if the precision is not specified, or is greater than the size of the -array, the array must contain a terminating -.B NUL -character. -.TP -.B p -The -.IR "" `` "void *" '' -pointer argument is printed in hexadecimal (as if by -.B %#x -or -.BR %#lx ). -.TP -.B n -The number of characters written so far is stored into the integer -indicated by the -.IR "" `` "int *" '' -(or variant) pointer argument. No argument is converted. -.TP -.B % -A `%' is written. No argument is converted. The complete conversion -specification is `%%'. -.PP -In no case does a non-existent or small field width cause truncation of a -field; if the result of a conversion is wider than the field width, the -field is expanded to contain the conversion result. -.PP -.SH EXAMPLES -.br -To print a date and time in the form `Sunday, July 3, 10:02', -where -.I weekday -and -.I month -are pointers to strings: -.RS -.nf -#include <stdio.h> -fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", - weekday, month, day, hour, min); -.fi -.RE -.PP -To print \*(Pi -to five decimal places: -.RS -.nf -#include <math.h> -#include <stdio.h> -fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0)); -.fi -.RE -.PP -To allocate a 128 byte string and print into it: -.RS -.nf -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -char *newfmt(const char *fmt, ...) -{ - char *p; - va_list ap; - if ((p = malloc(128)) == NULL) - return (NULL); - va_start(ap, fmt); - (void) vsnprintf(p, 128, fmt, ap); - va_end(ap); - return (p); -} -.fi -.RE -.SH "SEE ALSO" -.BR printf "(1), " scanf (3) -.SH STANDARDS -The -.BR fprintf , -.BR printf , -.BR sprintf , -.BR vprintf , -.BR vfprintf , -and -.B vsprintf -functions conform to ANSI C3.159-1989 (``ANSI C''). -.SH BUGS -Some floating point conversions under Linux cause memory leaks. -.PP -The conversion formats -.BR \&%D , -.BR \&%O , -and -.B %U -are not standard and are provided only for backward compatibility. These -may not be provided under Linux. -.PP -The effect of padding the -.B %p -format with zeros (either by the -.B 0 -flag or by specifying a precision), and the benign effect (i.e., none) of -the -.B # -flag on -.B %n -and -.B %p -conversions, as well as other nonsensical combinations such as -.BR %Ld , -are not standard; such combinations should be avoided. -.PP -Because -.B sprintf -and -.B vsprintf -assume an infinitely long string, callers must be careful not to overflow -the actual space; this is often impossible to assure. |
