vuoi
o PayPal
tutte le volte che vuoi
DESCRIPTION
The fprintf()
function places output on the named output stream. The function places output on the standard output stream (stdout
). The sprintf()
function places output followed by the null byte, '\0', in consecutive bytes starting at s; it is the user's responsibility to ensure that enough space is available. The snprintf()
function is identical to sprintf()
with the addition of the argument n, which states the size of the buffer referred to by s.
Each of these functions converts, formats, and prints its arguments under control of the format. The format is a character string, beginning and ending in its initial shift state, if any. The format string is composed of zero or more directives: ordinary characters, which are simply copied to the output stream, and each of which results in the fetching of zero or more arguments. The results are undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the
excessarguments are evaluated but are otherwise ignored.nth formatConversions can be applied to the argument after the in the argument list, ratherthan to the next unused argument. In this case, the conversion character % (see below) is%n$replaced by the sequence where n is a decimal integer in the range[1, {NL_ARGMAX}], giving the position of the argument in the argument list. This featureprovides for the definition of format strings that select arguments in an order appropriate tospecific languages (see the EXAMPLES section).%n$In format strings containing the form of conversion specifications, numbered argumentsin the argument list can be referenced from the format string as many times as required.In format strings containing the % form of conversion specifications, each argument in theargument list is used exactly once.fprintf()All forms of the functions allow for the insertion of a language-dependent radixcharacter in the output string. The radix character is defined in the
Il locale del programma (categoria LC_NUMERIC) è definito dalla variabile di ambiente. Nel locale POSIX, o in un locale in cui il carattere di separazione decimale non è definito, il carattere di separazione decimale predefinito è il punto (.). Ogni specifica di conversione è introdotta dal carattere % o dalla sequenza di caratteri $n, dopo di che appaiono in sequenza i seguenti elementi:
- flags: zero o più (in qualsiasi ordine), che modificano il significato della specifica di conversione.
- field width: un'opzionale larghezza minima del campo. Se il valore convertito ha meno byte della larghezza del campo, verrà riempito di spazi di default a sinistra; verrà riempito a destra se viene fornita la flag di allineamento a sinistra (-) alla larghezza del campo. La larghezza del campo può essere un asterisco (*), descritto di seguito, o un intero decimale.
- precision: un'opzionale che indica il numero minimo di cifre da visualizzare per le conversioni d, i, o, u, x e X; il numero di cifre da visualizzare dopo il carattere di separazione decimale.
Per ulteriori informazioni, consulta la documentazione di fprintf.
Il carattere per le conversioni "thee, E e f"; il numero massimo di cifre significative per le conversioni "g e G"; o il numero massimo di byte da stampare da una stringa nelle conversioni "s e S". La precisione ha la forma di un punto (.) seguito o da un asterisco (*), descritto di seguito, o da una stringa di cifre decimali opzionale, dove una stringa di cifre nulla viene trattata come 0. Se una precisione appare con qualsiasi altro carattere di conversione, il comportamento è indefinito. Un opzionale h specifica che un successivo carattere di conversione d, i, o, u, x o X si applica a un tipo o argomento di tipo (l'argomento sarà stato promosso secondo le promozioni integrali e il suo valore sarà convertito in tipo o prima della stampa); un opzionale h specifica che un successivo carattere di conversione n si applica a un puntatore a un argomento di tipo; un opzionale l (elle) specifica che un successivo carattere di conversione d, i, o, u, x o X si applica a un tipo o argomento; un- optional
l
(ell) specifying that alongint
orunsigned long int
followingn
conversion character applies to a pointer to a type argument; or anlong int
optionalL
specifying that a followinge
,E
,f
,g
orG
conversion character applies to a type argument. If anh
,l
orL
appears with any other conversion character,long double
the behaviour is undefined. - optional
l
specifying that a followingc
conversion character applies to awint_t
argument; an optionall
specifying that a followings
conversion character applies to a pointer to awchar_t
argument. - A conversion character that indicates the type of conversion to be applied.
- A field width, or precision, or both, may be indicated by an asterisk (
*
). In this case, an argument of type supplies the field width or precision. Arguments specifying field width,int
or precision, or both must appear in that order before the argument, if any, to be converted. A negative field width is taken as a-
flag followed by a positive field width. A negative%n
precision
is taken as if the precision were omitted. In format strings containing the form of a conversion specification, a field width or precision may be indicated by the sequence *m$
, where m
is a decimal integer in the range [1, {NL_ARGMAX}] giving the position in the argument list (after the format argument) of an integer argument containing the field width or precision, for example:
printf("%1$d:%2$.*3$d:%4$.*3$d\n", hour, min, precision, sec);
The %n$
format can contain either numbered argument specifications (that is, %n$
and *m$
) or unnumbered argument specifications (that is, %
and *
), but normally not both. The only exception to this is that %%
can be mixed with the %n$
form. The results of mixing numbered and unnumbered argument specifications in a string are undefined. When n
th numbered argument specifications are used, specifying the argument requires that all the leading arguments, from the
- The integer portion of the result of a decimal conversion (%i, %d, %u, %f, %g or %G) will be formatted with thousands' grouping characters. For other conversions the behaviour is undefined. The non-monetary grouping character is used.
- The result of the conversion will be left-justified within the field. The conversion will be right-justified if this flag is not specified.
- The result of a signed conversion will always begin with a sign (+ or -). The conversion will begin with a sign only when a negative value is converted if this flag is not specified.
- If the first character of a signed conversion is not a sign or if a signed conversion results in no characters, a space will be prefixed to the result. This means that if the space and + flags both appear, the space flag will be ignored.
- This flag specifies that the value is to be converted to an alternative form. For o conversion,
it increases the precision (if necessary) to force the first digit of the result to be 0. For x or X conversions, a non-zero result will have 0x (or 0X) prefixed to it. For e, E, f, g or G conversions, the result will always contain a radix character, even if no digits follow the radix character. Without this flag, a radix character appears in the result of these conversions only if a digit follows it. For g and G conversions, trailing not zeros will be removed from the result as they normally are. For other conversions, the behaviour is undefined. For d, i, o, u, x, X, e, E, f, g and G conversions, leading zeros (following any indication of sign or base) are used to pad to the field width; no space padding is performed. If the 0 and - flags both appear, the 0 flag will be ignored. For d, i, o, u, x and X conversions, if a precision is specified, the 0 flag will be ignored. If the 0 and ' flags both appear, the grouping characters are inserted before zero padding. For other conversions,
thebehaviour is undefined.
The conversion characters and their meanings are:
d, i
- The argument is converted to a signed decimal in the style[-]dddd
. 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 zeros. The default precision is 1. The result of converting 0 with an explicit precision of 0 is no characters.o
- The argument is converted to unsigned octal format in the styledddd
. 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 zeros. The default precision is 1. The result of converting 0 with an explicit precision of 0 is no characters.u
- The argument is converted to unsigned decimal format in the styledddd
. 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 zeros.
The argument is converted to unsigned hexadecimal format in the style unsigned intdddd; the letters abcdef are used. 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 zeros. The default precision is 1. The result of converting 0 with an explicit precision of 0 is no characters.
X Behaves the same as the x conversion character except that letters ABCDEF are used instead of abcdef.
The argument is converted to decimal notation in the style where double [-]ddd.ddd, the number of digits after the radix character is equal to the precision specification. If the precision is missing, it is taken as 6; if the precision is explicitly 0 and no # flag is present, no radix.
character appears. If a radix character appears, at least one digit appears before it. The value is rounded to the appropriate number of digits. Thefprintf()
family of functions may make available character string representations for infinity and NaN.e, E
The argument is converted in the style where there is one digit double [-]d.ddde±dd, before the radix character (which is non-zero if the argument is non-zero) 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 0 and no # flag is present, no radix character appears. The value is rounded to the appropriate number of digits. The E conversion character will produce a number with E instead of e introducing the exponent. The exponent always