![]() |
![]() |
![]() |
Compare two strings, up to a given length
#include <string.h> int strncmp( const char* s1, const char* s2, size_t n );
libc
The strncmp() function compares no more than n characters from the string pointed to by s1 to the string pointed to by s2.
#include <stdio.h> #include <string.h> #include <stdlib.h> int main( void ) { 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 ) ); return EXIT_SUCCESS; }
produces the output:
1 1 0 0
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
strcmp(), stricmp(), strnicmp()
![]() |
![]() |
![]() |