lstrcmpA function (winbase.h)

Compares two character strings. The comparison is case-sensitive.

To perform a comparison that is not case-sensitive, use the lstrcmpi function.

Syntax

int lstrcmpA(
  [in] LPCSTR lpString1,
  [in] LPCSTR lpString2
);

Parameters

[in] lpString1

Type: LPCTSTR

The first null-terminated string to be compared.

[in] lpString2

Type: LPCTSTR

The second null-terminated string to be compared.

Return value

Type: int

If the string pointed to by lpString1 is less than the string pointed to by lpString2, the return value is negative. If the string pointed to by lpString1 is greater than the string pointed to by lpString2, the return value is positive. If the strings are equal, the return value is zero.

Remarks

The lstrcmp function compares two strings by checking the first characters against each other, the second characters against each other, and so on until it finds an inequality or reaches the ends of the strings.

Note that the lpString1 and lpString2 parameters must be null-terminated, otherwise the string comparison can be incorrect.

The function calls CompareStringEx, using the current thread locale, and subtracts 2 from the result, to maintain the C run-time conventions for comparing strings.

The language (user locale) selected by the user at setup time, or through Control Panel, determines which string is greater (or whether the strings are the same). If no language (user locale) is selected, the system performs the comparison by using default values.

With a double-byte character set (DBCS) version of the system, this function can compare two DBCS strings.

The lstrcmp function uses a word sort, rather than a string sort. A word sort treats hyphens and apostrophes differently than it treats other symbols that are not alphanumeric, in order to ensure that words such as "coop" and "co-op" stay together within a sorted list. For a detailed discussion of word sorts and string sorts, see Handling Sorting in Your Applications.

Security Remarks

See Security Considerations: International Features for security considerations regarding choice of comparison functions.

Note

The winbase.h header defines lstrcmp as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winbase.h (include Windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See also

CompareString

CompareStringEx

CompareStringOrdinal

Conceptual

Other Resources

Reference

Strings

lstrcat

lstrcmpi

lstrcpy

lstrlen