compare two strings, up to a given length
#include <string.h> int strncmp( const char *s1, const char *s2, size_t n ); int _fstrncmp( const char __far *s1, const char __far *s2, size_t n );
The strncmp() function compares no more than n characters from the string pointed to by s1 to the string pointed to by s2.
The _fstrncmp() function is a data-model-independent form of the strncmp() function that accepts far pointer arguments. It's 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", strncmp( "abcdef", "abcDEF", 10 ) ); printf( "%d\n", strncmp( "abcdef", "abcDEF", 6 ) ); printf( "%d\n", strncmp( "abcdef", "abcDEF", 3 ) ); printf( "%d\n", strncmp( "abcdef", "abcDEF", 0 ) ); }
produces the output:
1 1 0 0
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
strcmp(), stricmp(), strnicmp()