The format is composed of zero or more directives: one or more white-space
characters, an ordinary character (neither ‘%
’
nor a white-space character), or a conversion specification.
Each conversion specification is introduced by the character ‘%
’.
After the ‘%
’, the following appear in sequence:
*
’.The formatted input function executes each directive of the format in turn. If a directive fails, the function returns. Failures are described as input failures (because of the occurrence of an encoding error or the unavailability of input characters), or matching failures (because of inappropriate input).
A directive composed of white-space character(s) is executed by reading input up to the first non-white-space character (which remains unread), or until no more characters can be read.
A directive that is an ordinary character is executed by reading the next characters of the stream. If any of those characters differ from the ones composing the directive, 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 being read, the directive fails.
A directive that is a conversion specification defines a set of matching input sequences, as described below for each specifier. A conversion specification is executed in the following steps:
[
’,
‘c
’, or ‘n
’
specifier.%
’ specifier, the
input item (or, in the case of a %n directive, the count of input characters)
is converted to a type appropriate to the conversion specifier. If the input
item is not a matching sequence, the execution of the directive fails: this
condition is a matching failure. Unless assignment suppression was indicated
by a ‘*
’, the result of the conversion is
placed in the object pointed to by the first argument following the format
argument that has not already received a conversion result. If this object
does not have an appropriate type, or if the result of the conversion cannot
be represented in the object, the behavior is undefined.The length modifiers and their meanings are:
hh
’d
’, ‘i
’,
‘o
’, ‘u
’,
‘x
’, ‘X
’,
or ‘n
’ conversion specifier applies to an
argument with type pointer to signed char or pointer to unsigned
char.h
’d
’, ‘i
’,
‘o
’, ‘u
’,
‘x
’, ‘X
’,
or ‘n
’ conversion specifier applies to an
argument with type pointer to short int or unsigned short int.l
’d
’, ‘i
’,
‘o
’, ‘u
’,
‘x
’, ‘X
’,
or ‘n
’ conversion specifier applies to an
argument with type pointer to long int or unsigned long int;
that a following ‘e
’, ‘E
’,
‘f
’, ‘F
’,
‘g
’, or ‘G
’
conversion specifier applies to an argument with type pointer to double.
Some CrossWorks library variants do not support the ‘l
’
length modifier in order to reduce code and data space requirements; please
ensure that you have selected the correct library in the Printf Integer
Support property of the project if you use this length modifier. ll
’d
’, ‘i
’,
‘o
’, ‘u
’,
‘x
’, ‘X
’,
or ‘n
’ conversion specifier applies to an
argument with type pointer to long long int or unsigned long long
int. Some CrossWorks library variants do not support the ‘ll
’
length modifier in order to reduce code and data space requirements; please
ensure that you have selected the correct library in the Printf Integer
Support property of the project if you use this length modifier.If a length modifier appears with any conversion specifier other than as specified
above, the behavior is undefined. Note that the C99 length modifiers ‘j
’,
‘z
’, ‘t
’, and
‘L
’ are not supported.
d
’i
’o
’u
’x
’e
’, ‘f
’,
‘g
’e
’, ‘f
’
and ‘F
’ conversion specifiers in order to
reduce code and data space requirements; please ensure that you have selected
the correct library in the Scanf Floating Point Support property of
the project if you use these conversion specifiers.c
’s
’[
’]
’.
The characters^
’,
in which case the scanset contains all characters that do not appear in the
scanlist between the circumflex and the right bracket. If the conversion specifier
begins with ‘[]
’ or‘[^]
’,
the right bracket character is in the scanlist and the next following right
bracket character is the matching right bracket that ends the specification;
otherwise the first following right bracket character is the one that ends
the specification. If a ‘-
’ character is in
the scanlist and is not the first, nor the second where the first character
is a ‘^
’, nor the last character, it is treated
as a member of the scanset. Some CrossWorks library variants do not support
the ‘[
’ conversion specifier in order to reduce
code and data space requirements; please ensure that you have selected the
correct library in the Scanf Classes Supported property of the project
if you use this conversion specifier.p
’%p
’
formatted output conversion. The corresponding argument must be a pointer
to a pointer to void.n
’%n
’ directive does not increment the
assignment count returned at the completion of execution of the fscanf function.
No argument is converted, but one is consumed. If the conversion specification
includes an assignment-suppressing character or a field width, the behavior
is undefined.%
’%
’ character; no conversion
or assignment occurs.Note that the C99 width modifier ‘l
’ used in
conjuction with the ‘c
’, ‘s
’,
and ‘[
’ conversion specifiers is not supported
and nor are the conversion specifiers ‘a
’ and
‘A
’.