function
<cwchar>
wctob
Convert wide character to single byte
Returns the single-byte representation of the wide character wc if (and only if) wc corresponds to a multibyte character with a length of a single byte in the initial state of a multibyte sequence.
Otherwise, it returns EOF.
Parameters
- wc
- The wint_t promotion of a wide character.
The value is internally converted to a wchar_t to be interpreted.
Return Value
If wc translates to a single-byte character in the initial shift state of a multibyte sequence, the function returns its representation as an unsigned char (promoted to a value of type int).
Otherwise, it returns EOF.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| /* wctob example */ #include <wchar.h> #include <stdio.h> int main() { int i,num; const wchar_t wcs [] = L"wctob example"; num=0; for (i=0; i<wcslen(wcs); ++i) if (wctob(wcs[i]) != EOF) ++num; wprintf (L"wcs contains %d characters that translate to single-byte characters.",num); return 0; }
|
Output:
wcs contains 14 characters that translate to single-byte characters. |
See also
- btowc
- Convert single byte character to wide character (function)
- wcrtomb
- Convert wide character to multibyte sequence (function)
- wcsrtombs
- Convert wide-character string to multibyte string (function)