strncmp

 

Description

Compare the first N characters of two strings.

Syntax

int strncmp( LPCSTR lpcszString1, LPCSTR lpcszString2, size_t count )

Parameters

lpcszString1
[input] First of two strings to compare
lpcszString2
[input] Second of two strings to compare
count
[input] Number of characters N to compare

Return

Returns an integer < 0 if the first N characters of string1 are alpha-numerically less than

string2, returns 0 if the first N characters of string1 are the same as string2, and returns

an integer > 0 if the first N characters of string1 are alpha-numerically greater than string2.

Examples

EX1

void strncmp_ex1()
{
    char str1[] = "Hello!!!";
    char str2[] = "Hello";        
    int nRet = strncmp(str1 , str2 , 5); // compare "Hello"
    out_int("nRet=", nRet); //output 0
    
    nRet = strncmp(str1 , str2 , 6);
    out_int("nRet=", nRet); //output 1
}

Remark

Compare the first N characters of two strings.

See Also

lstrcmp

header to Include

origin.h

Reference