SourcePoint Intel Help

Table of Contents

strncmp

Compare a portion of two strings.

Syntax

[result =] strncmp(string-expr1, string-expr2, expr)

Where:

result

specifies a debug object of type int2 to which the return value is assigned. If result is not specified, the return value is displayed on the next line of the screen.

string-expr1

specifies an nstring variable or a quoted string constant.

string-expr2

specifies an nstring variable or a quoted string constant.

expr

specifies a number or an expression that specifies the maximum number of characters to compare. 

Discussion

The strncmp command compares a specified maximum number of characters (expr) in two ASCII character strings. The comparison stops when a mismatch is found, when a null character is encountered in one of the strings, or when the specified number of characters have been compared. The return value depends on the difference between the values of the characters at the stopping position. The return value is one of the following:

-1

The final character in string-expr2 is greater than the final character in string-expr1.

0

The final character in string-expr2 is equal to the final character in string-expr1.

1

The final character in string-expr2 is less than the final character in string-expr1.

Example 1

Command input:

define nstring name1 = "rosenbaum"
define nstring name2 = "rosenberg"
define nstring name3 = "rosen"
strncmp(name1, name2, 7)

Result:

-1T

Example 2

Command input:

strncmp(name1, name3, 9)

Result:

1T

Example 3

Command input:

strncmp(name1, name3, 3)

Result:

0T

Related Topics: