Стандарт языка Си С99 TC (1113411), страница 53
Текст из файла (страница 53)
If there are insufficient arguments for the format,the behavior is undefined. If the format is exhausted while arguments remain, the excessarguments are evaluated (as always) but are otherwise ignored.3The format shall be a multibyte character sequence, beginning and ending in its initialshift state. The format is composed of zero or more directives: one or more white-spacecharacters, an ordinary multibyte character (neither % nor a white-space character), or aconversion specification. Each conversion specification is introduced by the character %.After the %, the following appear in sequence:— An optional assignment-suppressing character *.— An optional decimal integer greater than zero that specifies the maximum field width(in characters).282Library§7.19.6.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3— An optional length modifier that specifies the size of the receiving object.— A conversion specifier character that specifies the type of conversion to be applied.4The fscanf function executes each directive of the format in turn.
If a directive fails, asdetailed below, the function returns. Failures are described as input failures (due to theoccurrence of an encoding error or the unavailability of input characters), or matchingfailures (due to inappropriate input).5A directive composed of white-space character(s) is executed by reading input up to thefirst non-white-space character (which remains unread), or until no more characters canbe read.6A directive that is an ordinary multibyte character is executed by reading the nextcharacters of the stream. If any of those characters differ from the ones composing thedirective, the directive fails and the differing and subsequent characters remain unread.Similarly, if end-of-file, an encoding error, or a read error prevents a character from beingread, the directive fails.7A directive that is a conversion specification defines a set of matching input sequences, asdescribed below for each specifier.
A conversion specification is executed in thefollowing steps:8Input white-space characters (as specified by the isspace function) are skipped, unlessthe specification includes a [, c, or n specifier.250)9An input item is read from the stream, unless the specification includes an n specifier. Aninput item is defined as the longest sequence of input characters which does not exceedany specified field width and which is, or is a prefix of, a matching input sequence.251)The first character, if any, after the input item remains unread.
If the length of the inputitem is zero, the execution of the directive fails; this condition is a matching failure unlessend-of-file, an encoding error, or a read error prevented input from the stream, in whichcase it is an input failure.10Except in the case of a % specifier, the input item (or, in the case of a %n directive, thecount of input characters) is converted to a type appropriate to the conversion specifier. Ifthe input item is not a matching sequence, the execution of the directive fails: thiscondition is a matching failure.
Unless assignment suppression was indicated by a *, theresult of the conversion is placed in the object pointed to by the first argument followingthe format argument that has not already received a conversion result. If this objectdoes not have an appropriate type, or if the result of the conversion cannot be represented250) These white-space characters are not counted against a specified field width.251) fscanf pushes back at most one input character onto the input stream.
Therefore, some sequencesthat are acceptable to strtod, strtol, etc., are unacceptable to fscanf.§7.19.6.2Library283ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256in the object, the behavior is undefined.11The length modifiers and their meanings are:hhSpecifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to signed char or unsigned char.hSpecifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to short int or unsigned shortint.l (ell)Specifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to long int or unsigned longint; that a following a, A, e, E, f, F, g, or G conversion specifier applies toan argument with type pointer to double; or that a following c, s, or [conversion specifier applies to an argument with type pointer to wchar_t.ll (ell-ell) Specifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to long long int or unsignedlong long int.jSpecifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to intmax_t or uintmax_t.zSpecifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to size_t or the corresponding signedinteger type.tSpecifies that a following d, i, o, u, x, X, or n conversion specifier appliesto an argument with type pointer to ptrdiff_t or the correspondingunsigned integer type.LSpecifies that a following a, A, e, E, f, F, g, or G conversion specifierapplies to an argument with type pointer to long double.If a length modifier appears with any conversion specifier other than as specified above,the behavior is undefined.12The conversion specifiers and their meanings are:dMatches an optionally signed decimal integer, whose format is the same asexpected for the subject sequence of the strtol function with the value 10for the base argument.
The corresponding argument shall be a pointer tosigned integer.iMatches an optionally signed integer, whose format is the same as expectedfor the subject sequence of the strtol function with the value 0 for thebase argument. The corresponding argument shall be a pointer to signedinteger.284Library§7.19.6.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3oMatches an optionally signed octal integer, whose format is the same asexpected for the subject sequence of the strtoul function with the value 8for the base argument. The corresponding argument shall be a pointer tounsigned integer.uMatches an optionally signed decimal integer, whose format is the same asexpected for the subject sequence of the strtoul function with the value 10for the base argument. The corresponding argument shall be a pointer tounsigned integer.xMatches an optionally signed hexadecimal integer, whose format is the sameas expected for the subject sequence of the strtoul function with the value16 for the base argument.
The corresponding argument shall be a pointer tounsigned integer.a,e,f,g Matches an optionally signed floating-point number, infinity, or NaN, whoseformat is the same as expected for the subject sequence of the strtodfunction. The corresponding argument shall be a pointer to floating.cMatches a sequence of characters of exactly the number specified by the fieldwidth (1 if no field width is present in the directive).252)If no l length modifier is present, the corresponding argument shall be apointer to the initial element of a character array large enough to accept thesequence. No null character is added.If an l length modifier is present, the input shall be a sequence of multibytecharacters that begins in the initial shift state.
Each multibyte character in thesequence is converted to a wide character as if by a call to the mbrtowcfunction, with the conversion state described by an mbstate_t objectinitialized to zero before the first multibyte character is converted. Thecorresponding argument shall be a pointer to the initial element of an array ofwchar_t large enough to accept the resulting sequence of wide characters.No null wide character is added.sMatches a sequence of non-white-space characters.252)If no l length modifier is present, the corresponding argument shall be apointer to the initial element of a character array large enough to accept thesequence and a terminating null character, which will be added automatically.If an l length modifier is present, the input shall be a sequence of multibyte252) No special provisions are made for multibyte characters in the matching rules used by the c, s, and [conversion specifiers — the extent of the input field is determined on a byte-by-byte basis.