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 can qsort() sort an array of strings using pointers?ComputerScienceOne · Sorting Pointers to Elements
- How can comparator functions order Student structures?ComputerScienceOne · Comparator Functions
- Why can’t numeric comparison operators be used to compare strings in C?ComputerScienceOne · Comparing Strings and Characters
- Why can numeric comparison operators not be used to compare strings in C?ComputerScienceOne · Order of Precedence
- How does PHP compare strings with case-sensitive and case-insensitive functions?ComputerScienceOne · Tokenizing
- How do you compare strings in Java?ComputerScienceOne · Comparisons
- How do you implement a comparator for integers in C?ComputerScienceOne · Comparator Functions