blob: c942d3656182e4304c2b905468740d963b6769a5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<h1 id="firstHeading" class="firstHeading">wctob</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><wchar.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">int wctob( wint_t c );</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c95">(since C95)</span> </td> </tr> </table> <p>Narrows a wide character <code>c</code> if its multibyte character equivalent in the initial shift state is a single byte.</p>
<p>This is typically possible for the characters from the ASCII character set, since most multibyte encodings (such as UTF-8) use single bytes to encode those characters.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> c </td> <td> - </td> <td> wide character to narrow </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p><code><a href="../../io" title="c/io">EOF</a></code> if <code>c</code> does not represent a multibyte character with length <code>1</code> in initial shift state.</p>
<p>otherwise, the single-byte representation of <code>c</code> as <code>unsigned char</code> converted to <code>int</code></p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <assert.h>
void try_narrowing(wchar_t c)
{
int cn = wctob(c);
if(cn != EOF)
printf("%#x narrowed to %#x\n", c, cn);
else
printf("%#x could not be narrowed\n", c);
}
int main(void)
{
char* utf_locale_present = setlocale(LC_ALL, "th_TH.utf8");
assert(utf_locale_present);
puts("In Thai UTF-8 locale:");
try_narrowing(L'a');
try_narrowing(L'๛');
char* tis_locale_present = setlocale(LC_ALL, "th_TH.tis620");
assert(tis_locale_present);
puts("In Thai TIS-620 locale:");
try_narrowing(L'a');
try_narrowing(L'๛');
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">In Thai UTF-8 locale:
0x61 narrowed to 0x61
0xe5b could not be narrowed
In Thai TIS-620 locale:
0x61 narrowed to 0x61
0xe5b narrowed to 0xfb</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.29.6.1.2 The wctob function (p: 441) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.24.6.1.2 The wctob function (p: 387) </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="btowc" title="c/string/multibyte/btowc"> <span class="t-lines"><span>btowc</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c95">(C95)</span></span></span></div> </td> <td> widens a single-byte narrow character to wide character, if possible <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/string/multibyte/wctob" title="cpp/string/multibyte/wctob">C++ documentation</a></span> for <code>wctob</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/string/multibyte/wctob" class="_attribution-link">https://en.cppreference.com/w/c/string/multibyte/wctob</a>
</p>
</div>
|