memcmp()

Compare the bytes in two buffers

Synopsis:

#include <string.h>

int memcmp( const void* s1,
            const void* s2,
            size_t length );

Since:

BlackBerry 10.0.0

Arguments:

s1, s2
Pointers to the buffers that you want to compare.
length
The number of bytes that you want to compare.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The memcmp() function compares length bytes of the buffer pointed to by s1 to the buffer pointed to by s2.

Returns:

< 0
The object pointed to by s1 is less than the object pointed to by s2.
0
The object pointed to by s1 is equal to the object pointed to by s2.
> 0
The object pointed to by s1 is greater than the object pointed to by s2.

Examples:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main( void )
{
    char buffer[80];
    int retval;

    strcpy( buffer, "World" );
    
    retval = memcmp( buffer, "hello", 5 );
    if( retval < 0 ) {
        printf( "Less than\n" );
    } else if( retval == 0 ) {
        printf( "Equal to\n");
    } else {
        printf( "Greater than\n");
    }
    
    return EXIT_SUCCESS;
}

produces the output:

Less than

Classification:

ANSI, POSIX 1003.1

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus