The STRNCMP function is used to compare strings of a particular length.

Header file: string.h.

Int STRNCMP (const char *string1, const char *string2, size_t count); Table 2.4 describes the syntax parameters of the STRNCMP function.

Table 2.4 Parameter description

Parameter number describes string1 the given string string2 The length of the given string count to be compared

Return value: returns 1 if string1 is greater than string2; Is equal to, returns 0; Less than, return -1.

Example This example uses the STRNCMP function to compare strings of a specified length. int main() { char str1[]=”Hello”,str2[]=”Help”,str3[]=”Hello”; int a,b,c; A = STRNCMP (str1 str2, 3); String b = STRNCMP (str2,str3,4); Str2,str3 c = STRNCMP (str1,str2,4); / / compare strings str1, four characters before the str2 cout < < < < “\ t” < < b < < “\ t” < < c < < “\ n”; }

Running results:

0 1 to 1