compare two strings
#include <string.h> int strcmp( const char *s1, const char *s2 ); int _fstrcmp( const char __far *s1, const char __far *s2 );
The strcmp() function compares the string pointed to by s1 to the string pointed to by s2.
The _fstrcmp() function is a data-model-independent form of the strcmp() function that accepts far pointer arguments. It is most useful in mixed memory model applications.
Value | Meaning |
---|---|
< 0 | s1 is less than s2 |
0 | s1 is equal to s2 |
> 0 | s1 is greater than s2 |
#include <stdio.h> #include <string.h> void main() { printf( "%d\n", strcmp( "abcdef", "abcdef" ) ); printf( "%d\n", strcmp( "abcdef", "abc" ) ); printf( "%d\n", strcmp( "abc", "abcdef" ) ); printf( "%d\n", strcmp( "abcdef", "mnopqr" ) ); printf( "%d\n", strcmp( "mnopqr", "abcdef" ) ); }
produces the output:
0 1 -1 -1 1
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
strcmpi(), stricmp(), strncmp(), strnicmp()