6.23.6 btowc Function
Converts a character to an equivalent wide character.
Include
<wchar.h>
Prototype
wint_t btowc(int c);
Arguments
c
- the character to convert
Return Value
The function returns the character c
as wide character (type cast to type
wint_t
) provided that c
is a valid single-byte character
in the initial shift state of a multibyte sequence. Otherwise, or if c
is
EOF
, the function returns WEOF
.
Remarks
The function determines whether c
constitutes a valid single-byte character
in the initial shift state.
A multibyte character set may have a state-dependent encoding. Sequences begins in an initial shift state and enter other locale-specific shift states when specific multibyte characters are encountered. While in the initial shift state, all single-byte characters retain their usual interpretation and do not alter the shift state. The interpretation for subsequent bytes in the sequence is a function of the current shift state.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <wchar.h>
int main(void)
{
int i, num = 0;
const char mbs[] = "The quick brown fox\n";
for(i=0; i!=sizeof(mbs); i++)
if(btowc(mbs[i]) != WEOF)
num++;
wprintf(L"mbs contains %d single-byte characters.\n", num);
}
Example Output
mbs contains 21 single-byte characters.