memcmp()
QNX SDP8.0C Library ReferenceAPIDeveloper
Compare the bytes in two buffers
Synopsis:
#include <string.h>
int memcmp( const void* s1,
const void* s2,
size_t length );
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
Environment variables:
- LIBC_STRINGS
- On certain targets, you can use this environment variable to select the implementation of
memcmp().
The value is one of the strings given below.
- for AArch64 targets:
- generic — the default
- for AArch64 targets:
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | Yes |
Thread | Yes |
Page updated: