Home

fwscanf

fwscanf is a C standard library function that reads formatted input from a FILE* stream using wide-character formatting. It is the wide-character counterpart to fscanf and is used when working with wide-character data. The function is declared in stdio.h and uses a format string of type const wchar_t* to parse input from the given file stream.

Prototype and behavior: int fwscanf(FILE *stream, const wchar_t *format, ...); The format string specifies the expected input

Usage notes: The stream must be suitable for wide-character IO (the stream orientation and locale influence

---

pattern
with
wide-character
conversion
specifiers,
such
as
%lc
for
a
wide
character
or
%ls
for
a
wide
string,
and
other
standard
conversions
similar
to
fscanf.
The
corresponding
arguments
must
be
pointers
to
the
destinations
(for
example,
int*,
wchar_t*,
or
wchar_t[]).
The
function
consumes
input
from
the
stream
according
to
the
format
and
stores
the
results
in
the
provided
locations.
It
returns
the
number
of
input
items
successfully
matched
and
assigned,
which
may
be
fewer
than
requested.
If
end-of-file
is
encountered
before
any
conversion,
it
returns
EOF.
On
other
errors
or
input
failures,
a
value
less
than
the
number
of
conversions
requested
is
returned,
and
ferror
may
be
set.
conversions).
fwscanf
can
be
used
to
read
structured
data
from
files
much
like
fscanf,
but
with
wide-character
support.
Example:
FILE
*f
=
fopen("data.txt","r");
if
(f)
{
int
n;
wchar_t
word[100];
if
(fwscanf(f,
L"%d
%ls",
&n,
word)
==
2)
{
/*
success
*/
}
fclose(f);
}