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
|
<h1 id="firstHeading" class="firstHeading">mbsinit</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 mbsinit( const mbstate_t* ps);</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c95">(since C95)</span> </td> </tr> </table> <p>If <code>ps</code> is not a null pointer, the <code>mbsinit</code> function determines whether the pointed-to <code><a href="mbstate_t" title="c/string/multibyte/mbstate t">mbstate_t</a></code> object describes the initial conversion state.</p>
<h3 id="Notes"> Notes</h3> <p>Although a zero-initialized <code><a href="mbstate_t" title="c/string/multibyte/mbstate t">mbstate_t</a></code> always represents the initial conversion state, there may be other values of <code><a href="mbstate_t" title="c/string/multibyte/mbstate t">mbstate_t</a></code> that also represent the initial conversion state.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> ps </td> <td> - </td> <td> pointer to the mbstate_t object to examine </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p><code>0</code> if <code>ps</code> is not a null pointer and does not represent the initial conversion state, nonzero value otherwise.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
int main(void)
{
// allow mbrlen() to work with UTF-8 multibyte encoding
setlocale(LC_ALL, "en_US.utf8");
// UTF-8 narrow multibyte encoding
const char* str = u8"水"; // or u8"\u6c34" or "\xe6\xb0\xb4"
static mbstate_t mb; // zero-initialize
(void)mbrlen(&str[0], 1, &mb);
if (!mbsinit(&mb)) {
printf("After processing the first 1 byte of %s,\n"
"the conversion state is not initial\n\n", str);
}
(void)mbrlen(&str[1], strlen(str), &mb);
if (mbsinit(&mb)) {
printf("After processing the remaining 2 bytes of %s,\n"
"the conversion state is initial conversion state\n", str);
}
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">After processing the first 1 byte of 水,
the conversion state is not initial
After processing the remaining 2 bytes of 水,
the conversion state is initial conversion state</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.29.6.2.1 The mbsinit function (p: 322) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.29.6.2.1 The mbsinit function (p: 441-442) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.24.6.2.1 The mbsinit function (p: 387-388) </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="mbstate_t" title="c/string/multibyte/mbstate t"> <span class="t-lines"><span>mbstate_t</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> conversion state information necessary to iterate multibyte character strings <br> <span class="t-mark">(class)</span> </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/string/multibyte/mbsinit" title="cpp/string/multibyte/mbsinit">C++ documentation</a></span> for <code>mbsinit</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/mbsinit" class="_attribution-link">https://en.cppreference.com/w/c/string/multibyte/mbsinit</a>
</p>
</div>
|