Concept
How does strcmp() compare the contents of two strings in C?
ComputerScienceOne / Comparisons
"The C string library provides a standard comparator function to compare strings based on their content:\n\nint strcmp(const char *a, const char *b);\n\nThe function takes two strings and returns an integer based on the lexicographic ordering of a and b. If a precedes b, strcmp() returns something negative. It returns zero if a and b have the same content. Otherwise it returns something positive if b precedes a. Some examples:\n\n1 int x;\n\n2 x = strcmp(\"apple\", \"banana\"); //x is negative\n\n3 x = strcmp(\"zelda\", \"mario\"); //x is positive"
Related Ideas
- How does PHP compare strings using strcmp()?ComputerScienceOne · Comparisons
- How do you compare strings in Java?ComputerScienceOne · Comparisons
- How can comparison operators be used with characters in C?ComputerScienceOne · Comparing Strings and Characters
- Why can’t numeric comparison operators be used to compare strings in C?ComputerScienceOne · Comparing Strings and Characters
- How can you extract substrings from a string in PHP?ComputerScienceOne · Comparisons