Utility Functions and C Language Reference > C Language Reference > Alphabetical List of Functions > strncmp

strncmp

Example: strncmp String Manipulation Functions

Compares the first n characters of two strings.

int strncmp( constchar *string1, const char *string2, size_t n ); 

string1 The first string that is compared.
string2 The second string that is compared.
n The number of characters in each string that are compared.

Return Values

Returns a value indicating the lexicographical relation between the strings:

Return value Description
<0 string1 is less than string2
0 string1 is the same as string2
>0 string1 is greater than string2