Wikibooksβ

C Programming/string.h/strncmp

strncmp() is a standard-library function that compares two strings up to a specified length. The function is declared in string.h, and is compatible with the following prototype:

intstrncmp(constchar*s1,constchar*s2,size_tnum);

The function compares the strings using a lexicographical ordering, but never examines more than num characters. It returns zero if the strings are equal, or if their first num characters are equal; otherwise, it returns a negative integer if s1 is less than s2, and a positive integer if s1 is greater than s2. A simple implementation might be as follows: