11.4. Comparison Functions

11.4.1. The memcmp function

Synopsis
#include <string.h>

void *memcmp (void * s1 , void * s2 , size_t n );

Description

The memcmp function compares the first n characters of the object pointed to by s1 to the first n characters of the object pointed to by s2.

Returns

The memcmp function returns an integer greater than, equal to, or less than zero, accordingly as the object pointed to by s1 is greater than, equal to, or less than the object pointed to by s2.

See Also

Section 11.4.2

Section 11.4.3

Implementation Notes

None.

11.4.2. The strcmp function

Synopsis
#include <string.h>

void *strcmp (char * s1 , char * s2 );

Description

The strcmp function compares the string pointed to by s1 to the string pointed to by s2.

Returns

The strcmp function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2.

See Also

Section 11.4.3

Section 11.4.1

11.4.3. The strncmp function

Synopsis
#include <string.h>

void *strncmp (char * s1 , char * s2 , size_t n );

Description

The strncmp function compares not more than n characters (characters that follow a null character are not compared) from the array pointed to by s1 to the array pointed to by s2.

Returns

The strncmp function returns an integer greater than, equal to, or less than zero, accordingly as the possibly null-terminated array pointed to by s1 is greater than, equal to, or less than the possibly null-terminated array pointed to by s2.

See Also

Section 11.4.2

Implementation Notes

None.

11.4.4. The strcoll function

Synopsis
#include <string.h>

void *strcoll (char * s1 , char * s2 );

Description

The strcoll function compares the string pointed to by s1 to the string pointed to by s2, both interpreted as appropriate to the LC_COLLATE category of the current locale.

Returns

The strcoll function returns an integer greater than, equal to, or less than zero, accordingly as the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2, when they are both interpreted as appropriate to the current locale.

See Also

Section 11.4.2

Implementation Notes

11.4.5. The strxfrm function

Synopsis
#include <string.h>

size_t strxfrm (char * s1 , char * s2 , size_t n );

Description

The strxfrm function transforms the string pointed to by s2 and places the resulting string into the array pointed to by s1. The transformation is such that if the strcmpfunction is applied to two transformed strings, it returns a value greater than, equal to, or less than zero, corresponding to the result of the strcoll function applied to the same two original strings. No more than n characters are placed into the resulting array pointed to by s1, including the terminating null character. If n is zero, s1 is permitted to be a null pointer. If copying takes place between objects that overlap, the behavior is undefined.

Returns

The strxfrm function returns the length of the transformed string (not including the terminating null character). If the value returned is n or more, then the contents of the array pointed to be s1 are indeterminate.

Implementation Notes

In the XGC library, the strxfrm function copies the characters with no transformation.