strcmp
Header: <string.h>
Compares two null-terminated byte strings lexicographically.
# Declarations
int strcmp( const char* lhs, const char* rhs );
# Parameters
lhs, rhs: pointers to the null-terminated byte strings to compare
# Return value
Negative value if lhs appears before rhs in lexicographical order.
# Notes
This function is not locale-sensitive, unlike strcoll and strxfrm.
# Example
#include <stdio.h>
#include <string.h>
void demo(const char* lhs, const char* rhs)
{
const 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);
}