The fwscanf() function is defined in <cwchar> header file.
int fwscanf( FILE* stream, const wchar_t* format, ... );
The fwscanf() function reads the data from the file stream stream and stores the values into the respective variables.
Format Specifier | Description |
---|---|
% | Matches the literal % |
c | Matches a single character or multiple characters. If width is defined, matches exactly width characters. |
s | Matches consecutive non whitespace characters. If width is defined, matches exactly width characters or until first whitespace is found. |
[set] | Matches a non empty sequence of character from the given set of characters. If ^ is present at the beginning of set, then all the characters not in set are matched. |
d | Matches a decimal integer. |
i | Matches an integer. |
o | Matches an unsigned octal integer. |
X or x | Matches an unsigned hexadecimal integer. |
u | Matches an unsigned decimal integer. |
A or a, E or e, F or f, G or g | Matches a floating-point number. |
n | Returns the number of characters read so far. |
p | Matches an implementation defined character sequence defining a pointer. |
%[*][width][length]specifier
#include <cwchar>
#include <clocale>
#include <cwctype>
#include <cstdio>
int main()
{
FILE *fp = fopen("example.txt","w+");
wchar_t str[10], ch;
setlocale(LC_ALL, "en_US.UTF-8");
fwprintf(fp, L"%ls %lc", L"Summation", L'\u2211');
fwprintf(fp, L"%ls %lc", L"Integral", L'\u222b');
rewind(fp);
while((fwscanf(fp, L"%ls %lc", str, &ch))!=EOF)
{
wprintf(L"%lc is %ls\n", ch, str);
}
fclose(fp);
return 0;
}
∑ is Summation ∫ is Integral