||(Stream stream, String format [, Object obj1, ..., Object objN])
for characters matching
stores each match in the corresponding argument (when appropriate),
and returns the number of matches that were successfully stored, or
if there was an error before the first successful match.
string consists of zero or more components of the following types:
There should be general agreement between the type of
a conversion specification and the corresponding Object argument.
Each format conversion has the general form,
ordinary characters that must exactly match characters in the input
white space, any number of which matches any number of white space in the
corresponding relative position in the input stream (in other words, if you
match a number, then have 2 spaces in the format, then all white space after
the matched number is discarded from the input stream).
conversion specifications that determine how characters in
are converted into objects.
where the square brackets indicate optional elements and:
%[ * ][ ' ][ width ]specification
If you are a
indicates conversion should take place, but
that the actual assignment to the argument should be suppressed.
indicates that the number will have thousands separators
(e.g., commas) and these should be ignored in the number conversion.
indicates that only the number of characters specified by
should be converted from the input stream.
is one of:
matches up to the field width characters (1 by default),
and puts them in a string or an array without a trailing null character.
looks for a base-10 integer, which may be signed.
|e or E||
looks for a base-10 exponential number.
looks for a base-10 floating point number.
|g or G||
looks for a base-10 number.
looks for an integer, either base-10, base-8 or base-16
(base-8 is assumed if it starts with "0",
base-16 is assumed if it starts with "0x", otherwise base-10 is assumed).
assigns the current number of bytes read from
to the Object argument.
looks for a base-8 integer.
looks for an unsigned base-10 integer.
|x or X||
looks for a base-16 integer.
looks for a string up to the first white space.
matches the longest non-empty string of characters from the set enclosed
means match characters not listed in the set that immediately follows the
A range of characters can be specified as
matches a percent sign, but does not assign it.
programmer you probably will not have much trouble with the Yoix version of
but we made one important change that deserves mention.
works the way you might expect and copies non-white space characters into
fscanf(stream, "%s", buf);
also works, but it is not something you would try in
fscanf(stream, "%s", &buf);
The Yoix implementation of
collects characters from
and then takes a careful look at the argument that corresponds to the
In the first case it is a string,
so all it does is copy the characters into the space that is already been
In the second case the argument is
which is a pointer to a string, so this time
creates a new string using the characters just read from
and then it points
at that new string.
Here is a simple program
that shows how easily
can extract key/value pairs from lines that look like,
while (fscanf(stdin, "%[A-Z]=%[^\n]%*c", &key, &value) == 2)
printf("key=%s, value=%s\n", key, value);
in any input stream.
NAME=Sean Q. Public
ADDRESS=123 Main Street, Anytown, USA
| See Also:
Yoix is a registered trademark of AT&T Inc.