From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/string%2Fbyte%2Fstrcmp.html | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 devdocs/c/string%2Fbyte%2Fstrcmp.html (limited to 'devdocs/c/string%2Fbyte%2Fstrcmp.html') 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 @@ +

strcmp

Defined in header <string.h>
int strcmp( const char *lhs, const char *rhs );
+

Compares two null-terminated byte strings lexicographically.

+

The sign of the result is the sign of the difference between the values of the first pair of characters (both interpreted as unsigned char) that differ in the strings being compared.

+

The behavior is undefined if lhs or rhs are not pointers to null-terminated byte strings.

+

Parameters

+ +
lhs, rhs - pointers to the null-terminated byte strings to compare

Return value

Negative value if lhs appears before rhs in lexicographical order.

+

Zero if lhs and rhs compare equal.

+

Positive value if lhs appears after rhs in lexicographical order.

+

Notes

This function is not locale-sensitive, unlike strcoll and strxfrm.

+

Example

#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);
+}

Output:

+
[Hello World!] precedes [Hello!]
+[Hello World!] follows [Hello]
+[Hello World!] precedes [Hello there]
+[body!] equals [body!]

References

See also

+ + + + +
compares a certain amount of characters of two strings
(function)
+
(C95)
compares two wide strings
(function)
compares two buffers
(function)
compares two strings in accordance to the current locale
(function)
C++ documentation for strcmp
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/string/byte/strcmp +

+
-- cgit v1.2.3