strncmp
Compares a specified number of characters between two strings
#include <string.h> int strncmp ( const char *s1, const char *s2, size_t n);
The strncmp function returns an integer less than, equal to, or greater than 0, indicating that the string pointed to by s1 is less than, equal to, or greater than the string pointed to by s2.
The strncmp function compares not more than n characters from the string pointed to by s1 to the string pointed to by s2.
#include <string.h> #include <stdio.h> 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 following:
1 1 0 0