Compare

Compares two strings of the fixed length.

Syntax

IppStatus ippsCompare_8u(const Ipp8u* pSrc1, const Ipp8u* pSrc2, int len, int* pResult);

IppStatus ippsCompare_16u(const Ipp16u* pSrc1, const Ipp16u* pSrc2, int len, int* pResult);

Parameters

pSrc1

Pointer to the first source string.

pSrc2

Pointer to the second source string.

len

Maximum number of elements to be compared.

pResult

Pointer to the result.

Description

The function ippsCompare is declared in the ippch.h file. This function compares first len elements of two strings pSrc1 and pSrc2. The value pResult = pSrc1[i]- pSrc2[i] is computed successively for each i-th element, i =0,...len-1. When the first pair of non-matching elements occurs (that is, when pResult is not equal to zero), the function stops operation and returns the value pResult. The returned value is positive when pSrc1[i]> pSrc2[i] and negative when pSrc1[i]< pSrc2[i]. If the strings are equal, the function returns pResult = 0. The comparison is case-sensitive.

Example below shows how to use the function ippsCompare_8u.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error condition if at least one of the specified pointers is NULL.

ippStsLengthErr

Indicates an error condition if len is negative.

Using the Functions ippsCompare and ippsCompareIgnoreCaseLatin

 Ipp8u string0[] = "These functions compare two strings";
 Ipp8u string1[] = "These FUNCTIONS compare two strings";
 int result;
 ippsCompare_8u( string0, string1, sizeof (string0) - 1, &result );
 printf ( "ippsCompare_8u said: " );
 printf ( "string0 is %s string1.\n", (result < 0) ? "less than" :
 ((result > 0) ? "greater than" : "equal to") );
 ippsCompareIgnoreCaseLatin_8u( string0, string1, sizeof (string0) - 1,
 &result );
 printf ( "ippsCompareIgnoreCaseLatin_8u said: " );
 printf ( "string0 is %s string1.\n", (result < 0) ? "less than" :
 ((result > 0) ? "greater than" : "equal to") );

	
 Output:
 ippsCompare_8u said: string0 is greater than string1.
 ippsCompareIgnoreCaseLatin_8u said: string0 is equal to string1.

Submit feedback on this help topic

Copyright © 2000 - 2010, Intel Corporation. All rights reserved.