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
|
<h1 id="firstHeading" class="firstHeading">strpbrk</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><string.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">char *strpbrk( const char *dest, const char *breakset );</pre>
</td> <td> (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl t-since-c23"> <td> <pre data-language="c">/*QChar*/ *strpbrk( /*QChar*/ *dest, const char *breakset );</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> Scans the null-terminated byte string pointed to by <code>dest</code> for any character from the null-terminated byte string pointed to by <code>breakset</code>, and returns a pointer to that character.</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 character object type. <ul>
<li> If <code>dest</code> is of type <code>const T*</code>, the return type is <code>const char*</code>. </li>
<li> Otherwise, if <code>dest</code> is of type <code>T*</code>, the return type is <code>char*</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>(strpbrk)</code> or a function pointer is used), the actual function declaration <span class="t-v">(1)</span> becomes visible.</div> <p>The behavior is undefined if either <code>dest</code> or <code>breakset</code> is not a pointer to a null-terminated byte string.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> dest </td> <td> - </td> <td> pointer to the null-terminated byte string to be analyzed </td>
</tr> <tr class="t-par"> <td> breakset </td> <td> - </td> <td> pointer to the null-terminated byte string that contains the characters to search for </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>Pointer to the first character in <code>dest</code>, that is also in <code>breakset</code>, or null pointer if no such character exists.</p>
<h3 id="Notes"> Notes</h3> <p>The name stands for "string pointer break", because it returns a pointer to the first of the separator ("break") characters.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h>
#include <string.h>
int main(void)
{
const char* str = "hello world, friend of mine!";
const char* sep = " ,!";
unsigned int cnt = 0;
do {
str = strpbrk(str, sep); // find separator
if(str) str += strspn(str, sep); // skip separator
++cnt; // increment word count
} while(str && *str);
printf("There are %u words\n", cnt);
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">There are 5 words</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.24.5.4 The strpbrk function (p: 368) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.21.5.4 The strpbrk function (p: 331) </li></ul>
<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
<ul><li> 4.11.5.4 The strpbrk function </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="strcspn" title="c/string/byte/strcspn"> <span class="t-lines"><span>strcspn</span></span></a></div> </td> <td> returns the length of the maximum initial segment that consists <br> of only the characters not found in another byte string <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="strchr" title="c/string/byte/strchr"> <span class="t-lines"><span>strchr</span></span></a></div> </td> <td> finds the first occurrence of a character <br> <span class="t-mark">(function)</span> </td>
</tr> <tr class="t-dsc"> <td> <div><a href="strtok" title="c/string/byte/strtok"> <span class="t-lines"><span>strtok</span><span>strtok_s</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c11">(C11)</span></span></span></div> </td> <td> finds the next token in a byte 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/byte/strpbrk" title="cpp/string/byte/strpbrk">C++ documentation</a></span> for <code>strpbrk</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/byte/strpbrk" class="_attribution-link">https://en.cppreference.com/w/c/string/byte/strpbrk</a>
</p>
</div>
|