HP C/iX Library Reference Manual (30026-90004)
328 Chapter5
HP C/iX Library Function Descriptions
sscanf
character from the following input line:
" Hello, there!"
(Ten spaces followed by "Hello, there!"; the double quotes are added for clarity). If you use
%c, you get a space character. However, if you use %1s, you get "H" (the first nonspace
character in the input).
The [ conversion character also reads a character string from
string
. However, you
should use this character when a string is not to be delimited by space characters. The left
bracket is followed by a list of characters, and is terminated by a right bracket. If the first
character after the left bracket is a circumflex (^), characters are read from
string
until
a character is read that matches one of the characters between the brackets. If the first
character is not a circumflex, characters are read from
string
until a character not
occurring between the brackets is found. The corresponding item in the item list must
refer to a character array large enough to hold the characters read, plus a terminating null
character, which is added automatically. In some implementations, a minus sign (-) may
specify a range of characters.
The three string conversion characters provide you with a complete set of string-reading
capabilities. The c conversion character can be used to read any single character, or to read
a character string when the exact number of characters in the string is known beforehand.
The s conversion character enables you to read any character string that is delimited by
space characters and is of unknown length. Finally, the [ conversion character enables you
to read character strings that are delimited by characters other than space characters, and
which are of unknown length.
Floating-Point Conversion Characters
The e, f, and g (or E, F, and G, respectively) conversion characters read characters
from
string
until an inappropriate character is encountered, or until the number of
characters specified by the
field width
, if given, is exhausted (whichever comes first).
The e, f, and g characters expect data in the following form: an optionally signed string
of digits (possibly containing a decimal point), followed by an optional exponent field
consisting of an E or e followed by an optionally signed integer. Thus, an inappropriate
character is any character except +, -, ., 0 through 9, E, or e.
These floating-point conversion characters may be preceded by a lowercase L (l), to
indicate that a double value is expected rather than a float, or by an uppercase L (in
ANSI C) to indicate that a long double value is expected rather than a float. The
corresponding items in the item list for these conversion characters must be pointers to
floating-point variables of the appropriate length.
Literal Characters
Any characters included in the format that are not part of a conversion specification are
literal characters. A literal character is expected to occur in the input at exactly that point.
Note that since the percent sign is used to introduce a conversion specification, you must
type two percent signs (%%) to get a literal percent sign.