- Strcmp
In
POSIX and in theprogramming language C, strcmp is a function in theC standard library (declared instring.h ) that compares twoC string s.The prototype according ISO/IEC 9899:1999, 7.21.4.2 :
int strcmp(const char *s1, const char *s2);
strcmp
returns 0 when the strings are equal, a negative integer whens1
is less thans2
, or a positive integer ifs1
is greater thans2
, according to thelexicographical order .A variant of
strcmp
exists called
that only compares the strings up to a certain point.strncmp Example
The above code is a working sample that prints whether the first argument is less than, equal to or greater than the second.
A possible implementation is (P.J. Plauger, The Standard C Library, 1992):However, most real-world implementations will have various optimization tricks to reduce the execution time of the function.
Wikimedia Foundation. 2010.