summaryrefslogtreecommitdiff
path: root/devdocs/c/string%2Fmultibyte%2Fmbtowc.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/string%2Fmultibyte%2Fmbtowc.html
new repository
Diffstat (limited to 'devdocs/c/string%2Fmultibyte%2Fmbtowc.html')
-rw-r--r--devdocs/c/string%2Fmultibyte%2Fmbtowc.html56
1 files changed, 56 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fmultibyte%2Fmbtowc.html b/devdocs/c/string%2Fmultibyte%2Fmbtowc.html
new file mode 100644
index 00000000..7eed6100
--- /dev/null
+++ b/devdocs/c/string%2Fmultibyte%2Fmbtowc.html
@@ -0,0 +1,56 @@
+ <h1 id="firstHeading" class="firstHeading">mbtowc</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;stdlib.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-until-c99"> <td> <pre data-language="c">int mbtowc( wchar_t *pwc, const char *s, size_t n )</pre>
+</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-until-c99">(until C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">int mbtowc( wchar_t *restrict pwc, const char *restrict s, size_t n )</pre>
+</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <p>Converts a multibyte character whose first byte is pointed to by <code>s</code> to a wide character, written to <code>*pwc</code> if <code>pwc</code> is not null.</p>
+<p>If <code>s</code> is a null pointer, resets the global conversion state and determines whether shift sequences are used.</p>
+<h3 id="Notes"> Notes</h3> <p>Each call to <code>mbtowc</code> updates the internal global conversion state (a static object of type <code><a href="mbstate_t" title="c/string/multibyte/mbstate t">mbstate_t</a></code>, known only to this function). If the multibyte encoding uses shift states, care must be taken to avoid backtracking or multiple scans. In any case, multiple threads should not call <code>mbtowc</code> without synchronization: <code><a href="mbrtowc" title="c/string/multibyte/mbrtowc">mbrtowc</a></code> may be used instead.</p>
+<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> pwc </td> <td> - </td> <td> pointer to the wide character for output </td>
+</tr> <tr class="t-par"> <td> s </td> <td> - </td> <td> pointer to the multibyte character </td>
+</tr> <tr class="t-par"> <td> n </td> <td> - </td> <td> limit on the number of bytes in s that can be examined </td>
+</tr>
+</table> <h3 id="Return_value"> Return value</h3> <p>If <code>s</code> is not a null pointer, returns the number of bytes that are contained in the multibyte character or <code>-1</code> if the first bytes pointed to by <code>s</code> do not form a valid multibyte character or <code>​0​</code> if <code>s</code> is pointing at the null character <code>'\0'</code>.</p>
+<p>If <code>s</code> is a null pointer, resets its internal conversion state to represent the initial shift state and returns <code>​0​</code> if the current multibyte encoding is not state-dependent (does not use shift sequences) or a non-zero value if the current multibyte encoding is state-dependent (uses shift sequences).</p>
+<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;locale.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+#include &lt;string.h&gt;
+#include &lt;wchar.h&gt;
+
+// print multibyte string to wide-oriented stdout
+// equivalent to wprintf(L"%s\n", ptr);
+void print_mb(const char* ptr)
+{
+ mbtowc(NULL, 0, 0); // reset the conversion state
+ const char* end = ptr + strlen(ptr);
+ int ret = 0;
+ for (wchar_t wc; (ret = mbtowc(&amp;wc, ptr, end - ptr)) &gt; 0; ptr += ret)
+ wprintf(L"%lc", wc);
+ wprintf(L"\n");
+}
+
+int main(void)
+{
+ setlocale(LC_ALL, "en_US.utf8");
+ // UTF-8 narrow multibyte encoding
+ print_mb(u8"z\u00df\u6c34\U0001F34C"); // or u8"zß水🍌"
+}</pre></div> <p>Output:</p>
+<div class="text source-text"><pre data-language="c">zß水🍌</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C23 standard (ISO/IEC 9899:2023): </li>
+<ul><li> 7.24.7.2 The mbtowc function (p: TBD) </li></ul>
+<li> C17 standard (ISO/IEC 9899:2018): </li>
+<ul><li> 7.22.7.2 The mbtowc function (p: 260) </li></ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.22.7.2 The mbtowc function (p: 358) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 7.20.7.2 The mbtowc function (p: 322) </li></ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 4.10.7.2 The mbtowc function </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="mbrtowc" title="c/string/multibyte/mbrtowc"> <span class="t-lines"><span>mbrtowc</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> converts the next multibyte character to wide character, given state <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="mblen" title="c/string/multibyte/mblen"> <span class="t-lines"><span>mblen</span></span></a></div> </td> <td> returns the number of bytes in the next multibyte character <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/mbtowc" title="cpp/string/multibyte/mbtowc">C++ documentation</a></span> for <code>mbtowc</code> </td>
+</tr> </table> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 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/mbtowc" class="_attribution-link">https://en.cppreference.com/w/c/string/multibyte/mbtowc</a>
+ </p>
+</div>