strncmp

Compares two character strings

#include <strings.h>
long stncmp (
        const char *s1,
        const char *s2,
        size_t n
)

Arguments

s1 Pointer to string 1
s2 Pointer to string 2
n Number of characters to compare

Return Value

The result of the comparison is indicated in the return value as shown below:

Result Return Value
s1<s2 <0
s1=s2 =0
s1>s2 >0

Explanation

The first n characters of the string pointed to by s1 are compared to the corresponding characters of the string pointed to by s2, character-by-character as unsigned chars, and the result is indicated in the return value.