fwscanf(3C) fwscanf(3C)
NAME
fwscanf(), wscanf(), swscanf() - convert formatted wide-character input
SYNOPSIS
DESCRIPTION
The function reads from the named input stream.
The function reads from the standard input stream The reads from the wide-character string s.
Each function reads wide-characters, interprets them according to a format, and stores the results in its arguments. Each expects, as
arguments, a control wide-character string format described below, and a set of pointer arguments indicating where the converted input
should be stored. The result is undefined if there are insufficient arguments for the format. If the format is exhausted while arguments
remain, the excess arguments are evaluated but are otherwise ignored.
Conversions can be applied to the nth argument after the format in the argument list, rather than to the next unused argument. In this
case, the conversion wide-character (see below) is replaced by the sequence where n is a decimal integer in the range This feature provides
for the definition of format wide-character strings that select arguments in an order appropriate to specific languages. In format wide-
character strings containing the form of conversion specifications, it is unspecified whether numbered arguments in the argument list can
be referenced from the format wide-character string more than once.
The format can contain either form of a conversion specification, that is, or but the two forms cannot normally be mixed within a single
format wide-character string. The only exception to this is that or can be mixed with the form.
The function in all its forms allows for detection of a language-dependent radix character in the input string, encoded as a wide-character
value. The radix character is defined in the program's locale (category In the POSIX locale, or in a locale where the radix character is
not defined, the radix character defaults to a period
The format is a wide-character string composed of zero or more directives. Each directive is composed of one of the following:
o One or more white-space wide-characters (space, tab, newline, vertical-tab or form-feed characters);
o An ordinary wide-character (neither nor a white-space character); or
o A conversion specification.
Each conversion specification is introduced by a or the sequence after which the following appear in sequence:
o An optional assignment-suppressing character
o An optional non-zero decimal integer that specifies the maximum field width.
o An optional size modifier or indicating the size of the receiving object.
The conversion wide-characters and must be precede by (ell) if the corresponding argument is a pointer to rather than a pointer
to a character type.
The conversion wide-characters and must be preceded by if the corresponding argument is a pointer to short int rather than a
pointer to int, or by if it is a pointer to signed char, or by if it is a pointer to intmax_t, or by (ell) if it is a pointer to
long int, or by (ell-ell) if it is a pointer to long long, or by if it is a pointer to ptrdiff_t, or by if it is a pointer to
ssize_t.
Similarly, the conversion wide-characters and must be preceded by if the corresponding argument is a pointer to unsigned short
int rather than a pointer to unsigned int, or by if it is a pointer to unsigned char, or by if it is a pointer to uintmax_t, or
by (ell) if it is a pointer to unsigned long int, or by (ell-ell) if it is a pointer to unsigned long long, or by if it is a
pointer to unsigned ptrdiff_t, or by if it is a pointer to size_t.
The conversion wide-characters and must be preceded by (ell) if the corresponding argument is a pointer to double rather than a
pointer to float, or by if it is a pointer to long double. If an or appears with any other conversion wide-character, the behav-
ior is undefined.
o For Itanium(R)-based systems if the optional decimal floating point feature is installed and enabled, the following optional
character specifications are allowed:
An optional specifying that a following or conversion specifier applies to an argument with type pointer to
An optional specifying that a following or conversion specifier applies to an argument with type pointer to
An optional specifying that a following or conversion specifier applies to an argument with type pointer to
The behavior of the or conversion specifiers for decimal floating point numbers is the same as for double except hexadecimal
floating-point input is not accepted.
o A conversion wide-character that specifies the type of conversion to be applied. The valid conversion wide-characters are
described below.
The functions execute each directive of the format in turn. If a directive fails, as detailed below, the function returns. Failures are
described as input failures (due to the unavailability of input bytes) or matching failures (due to inappropriate input).
A directive composed of one or more white-space wide-characters is executed by reading input until no more valid input can be read, or up
to the first wide-character which is not a white-space wide-character, which remains unread.
A directive that is an ordinary wide-character is executed as follows. The next wide-character is read from the input and compared with
the wide-character that comprises the directive; if the comparison shows that they are not equivalent, the directive fails, and the differ-
ing and subsequent wide-characters remain unread.
A directive that is a conversion specification defines a set of matching input sequences, as described below for each conversion wide-char-
acter. A conversion specification is executed in the following steps:
Input white-space wide-characters (as specified by are skipped, unless the conversion specification includes a or n conversion character.
An item is read from the input, unless the conversion specification includes an conversion wide-character. An input item is defined as the
longest sequence of input wide-characters, not exceeding any specified field width, which is an initial subsequence of a matching sequence.
The first wide-character, if any, after the input item remains unread. If the length of the input item is 0, the execution of the conver-
sion specification fails; this condition is a matching failure, unless end-of-file, an encoding error, or a read error prevented input from
the stream, in which case it is an input failure. Except in the case of a conversion wide-character, the input item (or, in the case of a
conversion specification, the count of input wide-characters) is converted to a type appropriate to the conversion wide-character. If the
input item is not a matching sequence, the execution of the conversion specification 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 the conversion specification is introduced by or in the nth argu-
ment if introduced by the wide-character sequence If this object does not have an appropriate type, or if the result of the conversion can-
not be represented in the space provided, the behavior is undefined.
The following conversion wide-characters are valid:
Matches an optionally signed decimal integer, whose format is the same
as expected for the subject sequence of with the value 10 for the base argument. In the absence of a size modifier, the
corresponding argument must be a pointer to int.
Matches an optionally signed integer, whose format is the same as expected for
the subject sequence of with 0 for the base argument. In the absence of a size modifier, the corresponding argument must
be a pointer to int.
Matches an optionally signed octal integer, whose format is the same as
expected for the subject sequence of with the value 8 for the base argument. In the absence of a size modifier, the cor-
responding argument must be a pointer to unsigned int.
Matches an optionally signed decimal integer, whose format is
the same as expected for the subject sequence of with the value 10 for the base argument. In the absence of a size modi-
fier, the corresponding argument must be a pointer to unsigned int.
Matches an optionally signed hexadecimal integer, whose format is
the same as expected for the subject sequence of with the value 16 for the base argument. In the absence of a size modi-
fier, the corresponding argument must be a pointer to unsigned int.
Matches an optionally signed floating-point number,
whose format is the same as expected for the subject sequence of In the absence of a size modifier, the corresponding
argument must be a pointer to float.
If the family of functions generates character string representations for infinity and NaN (a 7858 symbolic entity encoded in floating-
point format) to support the ANSI/IEEE Std 754:1985 standard, the family of functions will recognize them as input.
Matches a sequence of non white-space wide-characters.
If no (ell) qualifier is present, characters from the input field are converted as if by repeated calls to the function,
with the conversion state described by an object initialized to zero before the first wide-character is converted. The
corresponding argument must be a pointer to a character array large enough to accept the sequence and the terminating null
character, which will be added automatically.
Otherwise, the corresponding argument must be a pointer to an array of large enough to accept the sequence and the terminating null wide-
character, which will be added automatically.
Matches a non-empty sequence of wide-characters from
a set of expected wide-characters (the scanset). If no (ell) qualifier is present, wide-characters from the input field
are converted as if by repeated calls to the function, with the conversion state described by an object initialized to
zero before the first wide-character is converted. The corresponding argument must be a pointer to a character array
large enough to accept the sequence and the terminating null character, which will be added automatically.
If an (ell) qualifier is present, the corresponding argument must be a pointer to an array of large enough to accept the sequence and the
terminating null wide-character, which will be added automatically.
The conversion specification includes all subsequent wide characters in the format string up to and including the matching right square
bracket ( The wide-characters between the square brackets (the scanlist) comprise the scanset, unless the wide-character after the left
square bracket is a circumflex ( in which case the scanset contains all wide-characters that do not appear in the scanlist between the cir-
cumflex and the right square bracket. If the conversion specification begins with or the right square bracket is included in the scanlist
and the next right square bracket is the matching right square bracket that ends the conversion specification; otherwise the first right
square bracket is the one that ends the conversion specification. If a is in the scanlist and is not the first wide-character, nor the
second where the first wide-character is a nor the last wide-character, the behavior is implementation-dependent.
Matches a sequence of wide-characters of the number specified by
the field width (1 if no field width is present in the conversion specification). If no (ell) qualifier is present, wide-
characters from the input field are converted as if by repeated calls to the function, with the conversion state described
by an object initialized to zero before the first wide-character is converted. The corresponding argument must be a
pointer to a character array large enough to accept the sequence. No null character is added. Otherwise, the correspond-
ing argument must be a pointer to an array of large enough to accept the sequence. No null wide-character is added.
Matches an implementation-dependent set of sequences, which must be
the same as the set of sequences that is produced by the conversion of the corresponding functions. The corresponding
argument must be a pointer to a pointer to void. If the input item is a value converted earlier during the same program
execution, the pointer that results will compare equal to that value; otherwise the behavior of the conversion is unde-
fined.
No input is consumed.
The corresponding argument must be a pointer to the integer into which is to be written the number of wide-characters read
from the input so far by this call to the functions. Execution of a conversion specification does not increment the
assignment count returned at the completion of execution of the function.
Same as
S Same as
Matches a single
no conversion or assignment occurs. The complete conversion specification must be
If a conversion specification is invalid, the behavior is undefined.
The conversion characters and are also valid and behave the same as, respectively, and
If end-of-file is encountered during input, conversion is terminated. If end-of-file occurs before any wide-characters matching the cur-
rent conversion specification (except for have been read (other than leading white-space, where permitted), execution of the current con-
version specification terminates with an input failure. Otherwise, unless execution of the current conversion specification is terminated
with a matching failure, execution of the following conversion specification (if any) is terminated with an input failure.
Reaching the end of the string in is equivalent to encountering end-of-file for
If conversion terminates on a conflicting input, the offending input is left unread in the input. Any trailing white space (including new-
line) is left unread unless matched by a conversion specification. The success of literal matches and suppressed assignments is only
directly determinable via the conversion specification.
The and functions may mark the field of the file associated with stream for update. The field will be marked for update by the first suc-
cessful execution of or using stream that returns data not supplied by a prior call to
APPLICATION USAGE
After or is applied to a stream, the stream becomes wide-oriented (see orientation(5)).
In format strings containing the form of conversion specifications, each argument in the argument list is used exactly once.
The prototypes of these functions are available to applications if they are:
a. conformant.
b. Compiled with macro with a value >=500.
c. Compiled with macro with a value >= 200112.
RETURN VALUE
Upon successful completion, these functions return the number of successfully matched and assigned input items; this number can be 0 in the
event of an early matching failure. If the input ends before the first matching failure or conversion, is returned. If a read error
occurs the error indicator for the stream is set, is returned, and is set to indicate the error.
ERRORS
For the conditions under which the functions will fail and may fail, refer to In addition, may fail if:
Input byte sequence does not form a valid character.
There are insufficient arguments.
Insufficient storage space is available.
In addition, may fail if:
The stream pointed to by
stream is byte-oriented.
In addition, may fail if:
is byte-oriented.
EXAMPLES
The call:
with the input line:
will assign to n the value 3, to i the value 25, x the value 5.432, and name will contain the string
The call:
with input:
will assign 56 to i, 789.0 to x, skip 0123, and place the string 56 in name. The next call to will return the character
AUTHOR
were developed by HP and Mitsubishi Electric Corporation.
SEE ALSO
fwprintf(3C), getwc(3C), setlocale(3C), wcstod(3C), wcstol(3C), wcrtomb(3C), wcstoul(3C), langinfo(5), orientation(5), thread_safety(5),
glossary(9).
fwscanf(3C)