Стандарт языка Си С99 TC (1113411), страница 51
Текст из файла (страница 51)
The argument modedetermines how stream will be buffered, as follows: _IOFBF causes input/output to befully buffered; _IOLBF causes input/output to be line buffered; _IONBF causesinput/output to be unbuffered. If buf is not a null pointer, the array it points to may beused instead of a buffer allocated by the setvbuf function239) and the argument sizespecifies the size of the array; otherwise, size may determine the size of a bufferallocated by the setvbuf function.
The contents of the array at any time areindeterminate.Returns3The setvbuf function returns zero on success, or nonzero if an invalid value is givenfor mode or if the request cannot be honored.7.19.6 Formatted input/output functions1The formatted input/output functions shall behave as if there is a sequence point after theactions associated with each specifier.240)7.19.6.1 The fprintf functionSynopsis1#include <stdio.h>int fprintf(FILE * restrict stream,const char * restrict format, ...);Description2The fprintf function writes output to the stream pointed to by stream, under controlof the string pointed to by format that specifies how subsequent arguments areconverted for output. If there are insufficient arguments for the format, the behavior isundefined.
If the format is exhausted while arguments remain, the excess arguments areevaluated (as always) but are otherwise ignored. The fprintf function returns whenthe end of the format string is encountered.3The format shall be a multibyte character sequence, beginning and ending in its initialshift state. The format is composed of zero or more directives: ordinary multibytecharacters (not %), which are copied unchanged to the output stream; and conversion239) The buffer has to have a lifetime at least as great as the open stream, so the stream should be closedbefore a buffer that has automatic storage duration is deallocated upon block exit.240) The fprintf functions perform writes to memory for the %n specifier.274Library§7.19.6.1WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3specifications, each of which results in fetching zero or more subsequent arguments,converting them, if applicable, according to the corresponding conversion specifier, andthen writing the result to the output stream.4Each conversion specification is introduced by the character %.
After the %, the followingappear in sequence:— Zero or more flags (in any order) that modify the meaning of the conversionspecification.— An optional minimum field width. If the converted value has fewer characters than thefield width, it is padded with spaces (by default) on the left (or right, if the leftadjustment flag, described later, has been given) to the field width.
The field widthtakes the form of an asterisk * (described later) or a nonnegative decimal integer.241)— An optional precision that gives the minimum number of digits to appear for the d, i,o, u, x, and X conversions, the number of digits to appear after the decimal-pointcharacter for a, A, e, E, f, and F conversions, the maximum number of significantdigits for the g and G conversions, or the maximum number of bytes to be written fors conversions. The precision takes the form of a period (.) followed either by anasterisk * (described later) or by an optional decimal integer; if only the period isspecified, the precision is taken as zero. If a precision appears with any otherconversion specifier, the behavior is undefined.— An optional length modifier that specifies the size of the argument.— A conversion specifier character that specifies the type of conversion to be applied.5As noted above, a field width, or precision, or both, may be indicated by an asterisk.
Inthis case, an int argument supplies the field width or precision. The argumentsspecifying field width, or precision, or both, shall appear (in that order) before theargument (if any) to be converted. A negative field width argument is taken as a - flagfollowed by a positive field width. A negative precision argument is taken as if theprecision were omitted.6The flag characters and their meanings are:-The result of the conversion is left-justified within the field.
(It is right-justified ifthis flag is not specified.)+The result of a signed conversion always begins with a plus or minus sign. (Itbegins with a sign only when a negative value is converted if this flag is not241) Note that 0 is taken as a flag, not as the beginning of a field width.§7.19.6.1Library275ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256specified.)242)space If the first character of a signed conversion is not a sign, or if a signed conversionresults in no characters, a space is prefixed to the result. If the space and + flagsboth appear, the space flag is ignored.7#The result is converted to an ‘‘alternative form’’. For o conversion, it increasesthe precision, if and only if necessary, to force the first digit of the result to be azero (if the value and precision are both 0, a single 0 is printed).
For x (or X)conversion, a nonzero result has 0x (or 0X) prefixed to it. For a, A, e, E, f, F, g,and G conversions, the result of converting a floating-point number alwayscontains a decimal-point character, even if no digits follow it. (Normally, adecimal-point character appears in the result of these conversions only if a digitfollows it.) For g and G conversions, trailing zeros are not removed from theresult. For other conversions, the behavior is undefined.0For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros(following any indication of sign or base) are used to pad to the field width ratherthan performing space padding, except when converting an infinity or NaN.
If the0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and Xconversions, if a precision is specified, the 0 flag is ignored. For otherconversions, the behavior is undefined.The length modifiers and their meanings are:hhSpecifies that a following d, i, o, u, x, or X conversion specifier applies to asigned char or unsigned char argument (the argument will havebeen promoted according to the integer promotions, but its value shall beconverted to signed char or unsigned char before printing); or thata following n conversion specifier applies to a pointer to a signed charargument.hSpecifies that a following d, i, o, u, x, or X conversion specifier applies to ashort int or unsigned short int argument (the argument willhave been promoted according to the integer promotions, but its value shallbe converted to short int or unsigned short int before printing);or that a following n conversion specifier applies to a pointer to a shortint argument.l (ell)Specifies that a following d, i, o, u, x, or X conversion specifier applies to along int or unsigned long int argument; that a following nconversion specifier applies to a pointer to a long int argument; that a242) The results of all floating conversions of a negative zero, and of negative values that round to zero,include a minus sign.276Library§7.19.6.1WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3following c conversion specifier applies to a wint_t argument; that afollowing s conversion specifier applies to a pointer to a wchar_targument; or has no effect on a following a, A, e, E, f, F, g, or G conversionspecifier.ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to along long int or unsigned long long int argument; or that afollowing n conversion specifier applies to a pointer to a long long intargument.jSpecifies that a following d, i, o, u, x, or X conversion specifier applies toan intmax_t or uintmax_t argument; or that a following n conversionspecifier applies to a pointer to an intmax_t argument.zSpecifies that a following d, i, o, u, x, or X conversion specifier applies to asize_t or the corresponding signed integer type argument; or that afollowing n conversion specifier applies to a pointer to a signed integer typecorresponding to size_t argument.tSpecifies that a following d, i, o, u, x, or X conversion specifier applies to aptrdiff_t or the corresponding unsigned integer type argument; or that afollowing n conversion specifier applies to a pointer to a ptrdiff_targument.LSpecifies that a following a, A, e, E, f, F, g, or G conversion specifierapplies to a long double argument.If a length modifier appears with any conversion specifier other than as specified above,the behavior is undefined.8The conversion specifiers and their meanings are:d,iThe int argument is converted to signed decimal in the style [−]dddd.
Theprecision specifies the minimum number of digits to appear; if the valuebeing converted can be represented in fewer digits, it is expanded withleading zeros. The default precision is 1. The result of converting a zerovalue with a precision of zero is no characters.o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigneddecimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; theletters abcdef are used for x conversion and the letters ABCDEF for Xconversion. The precision specifies the minimum number of digits to appear;if the value being converted can be represented in fewer digits, it is expandedwith leading zeros.
The default precision is 1. The result of converting azero value with a precision of zero is no characters.§7.19.6.1Library277ISO/IEC 9899:TC3f,FCommittee Draft — Septermber 7, 2007WG14/N1256A double argument representing a floating-point number is converted todecimal notation in the style [−]ddd.ddd, where the number of digits afterthe decimal-point character is equal to the precision specification. If theprecision is missing, it is taken as 6; if the precision is zero and the # flag isnot specified, no decimal-point character appears. If a decimal-pointcharacter appears, at least one digit appears before it.