VMS Help
CC, Run-time functions, sscanf
*Conan The Librarian (sorry for the slow response - running on an old VAX)
|
|
Performs formatted input from a character string in memory.
Syntax:
#include <stdio.h>
int sscanf(const char *string, const char *format_string,...);
where the ... represents optional expressions that are pointers to
objects whose resultant types correspond to conversion
specifications given in the format_string. If no conversion
specifications are given, you can omit the input pointers.
Otherwise, the function calls must have at least as many input
pointers as there are conversion specifications, and the conversion
specifications must match the types of the input pointers.
Conversion specifications are matched to input sources in
left-to-right order.
The format string for the input of information can include three
kinds of items:
o White-space characters (spaces, tabs, and new-line characters),
which match optional white-space characters in the input field.
o Ordinary characters (not %), which must match the next
nonwhite-space character in the input.
o Conversion specifications, which govern the conversion of the
characters in an input field and their assignment to an object
indicated by a corresponding input pointer.
A conversion specification consists of the following characters, in
the order listed:
o A percent character (%) or the sequence %n$ (where n is an
integer).
The sequence %n$ denotes that the conversion is applied to
the nth input pointer listed, where n is a decimal integer
between [1, NL_ARGMAX] (see the <limits.h> header file).
For example, a conversion specification beginning %5$ means
that the conversion will be applied to the 5th input
pointer listed after the format specification. The
sequence %$ is invalid. If the conversion specification
does not begin with the sequence %n$ the conversion
specification is matched to its input pointer in
left-to-right order. You should only use one type of
conversion specification (% or %n$) in a format
specification.
o One or more optional characters
o A conversion specifier.
* Assignment-suppressing character.
field width Nonzero decimal integer that specifies the maximum
field width.
h, l, or L Precede a conversion specifier of d, i, or n with an h
if the corresponding argument is a pointer to short int
rather than a pointer to int, or with an l (lowercase
ell) if it is a pointer to long int.
Similarly, precede a conversion specifier of o, u, or x
with an h if the corresponding argument is a pointer to
unsigned short int rather than a pointer to unsigned
int, or with an l (lowercase ell) if it is a pointer to
unsigned long int.
Finally, precede a conversion specifier of e, f, or g
with an l (lowercase ell) if the corresponding argument
is a pointer to double rather than a pointer to float,
or with an L if it is a pointer to long double.
If an h, l, or L appears with any other conversion
specifier, the behavior is undefined.
d Expects a decimal integer in the input whose format is
the same as expected for the subject sequence of the
strtol function with the value 10 for the base
argument. The corresponding argument must be a pointer
to int.
i Expects an integer whose type is determined by the
leading input characters. For example, a leading 0 is
equated to octal, a leading 0X is equated to
hexadecimal, and all other forms are equated to
decimal. The corresponding argument must be a pointer
to int.
o Expects an octal integer in the input (with or without
a leading 0). The corresponding argument must be a
pointer to int.
u Expects a decimal integer in the input whose format is
the same as expected for the subject sequence of the
strtoul function with the value 10 for the base
argument.
x Expects a hexadecimal integer in the input (with or
without a leading 0x). The corresponding argument must
be a pointer to unsigned int.
c Expects a single byte in the input. The corresponding
argument must be a pointer to char. If a field width
precedes the c conversion specifier, the number of
characters specified by the field width is read. In
this case, the corresponding argument must be a pointer
to an array of char.
C Expects a multibyte character in the input which is
converted into a wide character code. The
corresponding argument must be a pointer to type
wchar_t. If a field width precedes the C conversion
specifier, the number of characters specified by the
field width is read; in this case, the corresponding
argument must be a pointer to array of wchar_t.
s Expects a sequences of bytes in the input. The
corresponding argument must be a pointer to an array of
characters that is large enough to contain the sequence
plus a terminating null character, which is added
automatically. The input field is terminated by a
space, tab, or new-line character.
S Expects a sequence of multibyte characters in the
input, which are converted to wide-character codes.
The corresponding argument must be a pointer to an
array of wide characters (type wchar_t) that is large
enough to contain the sequence plus a terminating null
wide-character code which is added automatically. The
input field is terminated by a space, tab, or new-line
character.
e,f,g Expects a floating-point number in the input. The
corresponding argument must be a pointer to float. The
input format for floating-point numbers is:
[+|-]nnn[radix][ddd][{E|e}[+|-]nn]
The n's and d's are decimal digits (as many as
indicated by the field width minus the signs and the
letter E). The radix character is defined in the
current locale.
[...] Expects a nonempty sequence of characters that is not
delimited by a white-space character. The brackets
enclose a set of characters (the scanset) expected in
the input sequence. Any character in the input
sequence that does not match a character in the scanset
terminates the character sequence. The corresponding
argument must be a pointer to an array of characters.
All characters between the brackets comprise the
scanset, unless the first character after the left
bracket is a circumflex (^). In this case, the scanset
contains all characters other than those that appear
between the circumflex and the right bracket; that is,
any character that does appear between the circumflex
and the right bracket will terminate the input
character sequence.
If the conversion specifier begins with [] or [^], the
right-bracket character is in the scanset and the next
right-bracket character is the matching right bracket
that ends the specification; otherwise, the first right
bracket character ends the specification.
p An argument that is a pointer to void. The input value
is interpreted as a hexadecimal value.
n No input is consumed. The corresponding argument is a
pointer to an integer. The integer is assigned the
number of characters read from the input stream so far
by this call to the formatted input function.
Execution of a %n directive does not increment the
assignment count returned when the formatted input
function completes execution.
% Matches a single percent symbol. No conversion or
assignment takes place. The complete conversion
specification would be %%.
[legal]
[privacy]
[GNU]
[policy]
[netiquette]
[sponsors]
[FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.