6.23.57 wctob Function
Converts a wide character to an equivalent single-byte character.
Include
<wchar.h>
Prototype
int wctob(wint_t c);
Arguments
c
- the wide character to convert
Return Value
The function returns the character c
as single-byte character (converted to
type int
) provided that c
is a valid single-byte character
in the initial shift state of a multibyte sequence. Otherwise, the function returns
EOF
.
Remarks
The function determines whether c
is a member of the extended character set
whose multibyte character representation is a single byte when 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(wctob(mbs[i]) != EOF)
++num;
wprintf(L"mbs contains %d wide characters that translate to single-byte characters.\n", num);
}
Example Output
mbs contains 21 wide characters that translate to single-byte characters.