summaryrefslogtreecommitdiff
path: root/devdocs/c/string%2Fbyte%2Fstrchr.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%2Fbyte%2Fstrchr.html
new repository
Diffstat (limited to 'devdocs/c/string%2Fbyte%2Fstrchr.html')
-rw-r--r--devdocs/c/string%2Fbyte%2Fstrchr.html45
1 files changed, 45 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fbyte%2Fstrchr.html b/devdocs/c/string%2Fbyte%2Fstrchr.html
new file mode 100644
index 00000000..39e66671
--- /dev/null
+++ b/devdocs/c/string%2Fbyte%2Fstrchr.html
@@ -0,0 +1,45 @@
+ <h1 id="firstHeading" class="firstHeading">strchr</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;string.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl"> <td> <pre data-language="c">char *strchr( const char *str, int ch );</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*/ *strchr( /*QChar*/ *str, int 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 <code>ch</code> (after conversion to <code>char</code> as if by <code>(char)ch</code>) in the null-terminated byte string pointed to by <code>str</code> (each character interpreted as <code>unsigned char</code>). The terminating null character is considered to be a part of the string and can be found when searching for <code>'\0'</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 character object type. <ul>
+<li> If <code>str</code> is of type <code>const T*</code>, the return type is <code>const char*</code>. </li>
+<li> Otherwise, if <code>str</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>(strchr)</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 <code>str</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> str </td> <td> - </td> <td> pointer to the null-terminated byte string to be analyzed </td>
+</tr> <tr class="t-par"> <td> ch </td> <td> - </td> <td> 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 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 &lt;stdio.h&gt;
+#include &lt;string.h&gt;
+
+int main(void)
+{
+ const char *str = "Try not. Do, or do not. There is no try.";
+ char target = 'T';
+ const char *result = str;
+
+ while((result = strchr(result, target)) != NULL) {
+ printf("Found '%c' starting at '%s'\n", target, result);
+ ++result; // Increment result, otherwise we'll find target at the same location
+ }
+}</pre></div> <p>Output:</p>
+<div class="text source-text"><pre data-language="c">Found 'T' starting at 'Try not. Do, or do not. There is no try.'
+Found 'T' starting at 'There is no try.'</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.24.5.2 The strchr function (p: 367-368) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 7.21.5.2 The strchr function (p: 330) </li></ul>
+<li> C89/C90 standard (ISO/IEC 9899:1990): </li>
+<ul><li> 4.11.5.2 The strchr function </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="memchr" title="c/string/byte/memchr"> <span class="t-lines"><span>memchr</span></span></a></div> </td> <td> searches an array for the first occurrence of a character <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="strrchr" title="c/string/byte/strrchr"> <span class="t-lines"><span>strrchr</span></span></a></div> </td> <td> finds the last occurrence of a character <br> <span class="t-mark">(function)</span> </td>
+</tr> <tr class="t-dsc"> <td> <div><a href="strpbrk" title="c/string/byte/strpbrk"> <span class="t-lines"><span>strpbrk</span></span></a></div> </td> <td> finds the first location of any character in one string, in another 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/strchr" title="cpp/string/byte/strchr">C++ documentation</a></span> for <code>strchr</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/byte/strchr" class="_attribution-link">https://en.cppreference.com/w/c/string/byte/strchr</a>
+ </p>
+</div>