diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/string%2Fbyte%2Fstrcmp.html | |
new repository
Diffstat (limited to 'devdocs/c/string%2Fbyte%2Fstrcmp.html')
| -rw-r--r-- | devdocs/c/string%2Fbyte%2Fstrcmp.html | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/devdocs/c/string%2Fbyte%2Fstrcmp.html b/devdocs/c/string%2Fbyte%2Fstrcmp.html new file mode 100644 index 00000000..40219714 --- /dev/null +++ b/devdocs/c/string%2Fbyte%2Fstrcmp.html @@ -0,0 +1,50 @@ + <h1 id="firstHeading" class="firstHeading">strcmp</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 class="t-dcl-nopad"> <pre data-language="c">int strcmp( const char *lhs, const char *rhs );</pre> +</td> <td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> </table> <p>Compares two null-terminated byte strings lexicographically.</p> +<p>The sign of the result is the sign of the difference between the values of the first pair of characters (both interpreted as <code>unsigned char</code>) that differ in the strings being compared.</p> +<p>The behavior is undefined if <code>lhs</code> or <code>rhs</code> are not pointers to null-terminated byte strings.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> lhs, rhs </td> <td> - </td> <td> pointers to the null-terminated byte strings to compare </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p>Negative value if <code>lhs</code> appears before <code>rhs</code> in lexicographical order.</p> +<p>Zero if <code>lhs</code> and <code>rhs</code> compare equal.</p> +<p>Positive value if <code>lhs</code> appears after <code>rhs</code> in lexicographical order.</p> +<h3 id="Notes"> Notes</h3> <p>This function is not locale-sensitive, unlike <code><a href="strcoll" title="c/string/byte/strcoll">strcoll</a></code> and <code><a href="strxfrm" title="c/string/byte/strxfrm">strxfrm</a></code>.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <string.h> +#include <stdio.h> + +void demo(const char* lhs, const char* rhs) +{ + int rc = strcmp(lhs, rhs); + const char *rel = rc < 0 ? "precedes" : rc > 0 ? "follows" : "equals"; + printf("[%s] %s [%s]\n", lhs, rel, rhs); +} + +int main(void) +{ + const char* string = "Hello World!"; + demo(string, "Hello!"); + demo(string, "Hello"); + demo(string, "Hello there"); + demo("Hello, everybody!" + 12, "Hello, somebody!" + 11); +}</pre></div> <p>Output:</p> +<div class="text source-text"><pre data-language="c">[Hello World!] precedes [Hello!] +[Hello World!] follows [Hello] +[Hello World!] precedes [Hello there] +[body!] equals [body!]</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.24.4.2 The strcmp function (p: 365-366) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.21.4.2 The strcmp function (p: 328-329) </li></ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 4.11.4.2 The strcmp function </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="strncmp" title="c/string/byte/strncmp"> <span class="t-lines"><span>strncmp</span></span></a></div> </td> <td> compares a certain amount of characters of two strings <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="../wide/wcscmp" title="c/string/wide/wcscmp"> <span class="t-lines"><span>wcscmp</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> compares two wide strings <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="memcmp" title="c/string/byte/memcmp"> <span class="t-lines"><span>memcmp</span></span></a></div> </td> <td> compares two buffers <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="strcoll" title="c/string/byte/strcoll"> <span class="t-lines"><span>strcoll</span></span></a></div> </td> <td> compares two strings in accordance to the current locale <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/strcmp" title="cpp/string/byte/strcmp">C++ documentation</a></span> for <code>strcmp</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/strcmp" class="_attribution-link">https://en.cppreference.com/w/c/string/byte/strcmp</a> + </p> +</div> |
