CHAPTER 10 LIBRARY FUNCTIONS
User
’
s Manual U15556EJ1V0UM
184
sscanf
I/O Functions
s
................. Inputs a character string consisting of a non-blank character string.
The corresponding
argument is a pointer to an integer. 0x or 0X can be allocated at the first hexadecimal integer.
The corresponding argument must be a pointer an array that has sufficient size to
accommodate this character string and a null terminator. The null terminator will be
automatically added.
[
.................. Inputs a character string consisting of expected character groups (called a
scanset
). The
corresponding argument must be a pointer to the first character of an array that has sufficient
size to accommodate this character string and a null terminator. The null terminator will be
automatically added. The format commands continue from this character up to the closing
square bracket (]). The character string (called a
scanlist
) enclosed in the square brackets
constitutes a
scanset
except when the character immediately after the opening square
bracket is a circumflex (^).
When the character is a circumflex, all the characters other than a
scanlist
between the
circumflex and the closing square bracket constitute a
scanset
. However, when a
scanlist
begins with [ ] or [^], this closing square bracket is contained in the
scanlist
and the next
closing square brocket becomes the end of the
scanlist
. A hyphen (
–
) at other than the left or
right end of a
scanlist
is interpreted as the punctuation mark for hyphenation if the character
at the left of the range specifying hyphen (
–
) is not smaller than the right-hand character in
ASCII code value.
c
................. Inputs a character string consisting of the number of characters specified by the field width. (If
the field width specification is omitted, 1 is assumed.) The corresponding argument must be a
pointer to the first character of an array that has sufficient size to accommodate this character
string. The null terminator will not be added.
p
................. Reads an unsigned hexadecimal integer. The corresponding argument must be a pointer to
void
pointer. For the large model, a hexadecimal 8-digit integer is input, and the higher two
digits are ignored.
n
................. Receives no input from the string
s
. The corresponding argument must be a pointer to an
integer. The number of characters that are read thus far by this function from the string
“
s
”
is
stored in the object that is pointed to by this pointer. The %n format command is not included
in the return value assignment count.
%
................ Reads a % sign. Neither conversion nor assignment takes place.
If a format specification is invalid, the format command execution fails.
If a null terminator appears in the input stream,
sscanf
will terminate.
If an overflow occurs in an integer conversion (with the
d, i, o, u, x,
or
p
format specifier), the higher bits will
be truncated depending on the number of bits of the data type after the conversion.
The syntax of input
format
commands is illustrated below.