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">wcschr</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 t-since-c95"> <td> <pre data-language="c">wchar_t *wcschr( const wchar_t *str, wchar_t ch );</pre>
</td> <td> (1) </td> <td> <span class="t-mark-rev t-since-c95">(since C95)</span> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">/*QWchar_t*/ *wcschr( /*QWchar_t*/ *str, wchar_t ch );</pre>
</td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> </tr> </table> <div class="t-li1">
<span class="t-li">1)</span> Finds the first occurrence of the wide character <code>ch</code> in the wide string pointed to by <code>str</code>.</div> <div class="t-li1">
<span class="t-li">2)</span> Type-generic function equivalent to <span class="t-v">(1)</span>. Let <code>T</code> be an unqualified wide character object type. <ul>
<li> If <code>str</code> is of type <code>const T*</code>, the return type is <code>const wchar_t*</code>. </li>
<li> Otherwise, if <code>str</code> is of type <code>T*</code>, the return type is <code>wchar_t*</code>. </li>
<li> Otherwise, the behavior is undefined. </li>
</ul> If a macro definition of each of these generic functions is suppressed to access an actual function (e.g. if <code>(wcschr)</code> or a function pointer is used), the actual function declaration <span class="t-v">(1)</span> becomes visible.</div> <h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> str </td> <td> - </td> <td> pointer to the null-terminated wide string to be analyzed </td>
</tr> <tr class="t-par"> <td> ch </td> <td> - </td> <td> wide character to search for </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>Pointer to the found character in <code>str</code>, or a null pointer if no such character is found.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <wchar.h>
#include <stdio.h>
#include <locale.h>
int main(void)
{
wchar_t arr[] = L"白猫 黒猫 кошки";
wchar_t *cat = wcschr(arr, L'猫');
wchar_t *dog = wcschr(arr, L'犬');
setlocale(LC_ALL, "en_US.utf8");
if(cat)
printf("The character 猫 found at position %td\n", cat-arr);
else
puts("The character 猫 not found");
if(dog)
printf("The character 犬 found at position %td\n", dog-arr);
else
puts("The character 犬 not found");
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">The character 猫 found at position 1
The character 犬 not found</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.29.4.5.1 The wcschr function (p: 435) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.24.4.5.1 The wcschr function (p: 381) </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="wcsrchr" title="c/string/wide/wcsrchr"> <span class="t-lines"><span>wcsrchr</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> finds the last occurrence of a wide character in a wide string <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="wcspbrk" title="c/string/wide/wcspbrk"> <span class="t-lines"><span>wcspbrk</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> finds the first location of any wide character in one wide string, in another wide string <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/wide/wcschr" title="cpp/string/wide/wcschr">C++ documentation</a></span> for <code>wcschr</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/wide/wcschr" class="_attribution-link">https://en.cppreference.com/w/c/string/wide/wcschr</a>
</p>
</div>
|