[Previous] [Contents] [Next]

bcmp()

Compare a given number of characters in two strings

Synopsis:

#include <strings.h>

int bcmp( const void *s1, 
          const void *s2, 
          size_t n );

Library:

libc

Description:

The bcmp() function compares the byte string pointed to by s1 to the string pointed to by s2. The number of bytes to compare is specified by n. NUL characters may be included in the comparison.


Note: This function is similar to the ANSI memcmp() function, but tests only for equality. New code should use the ANSI function.

Returns:

0
The byte strings are identical.
1
The byte strings aren't identical.

Examples:

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

int main( void )
  {
    if( bcmp( "Hello there", "Hello world", 6 ) ) {
      printf( "Not equal\n" );
    } else {
      printf( "Equal\n" );
    }
    return EXIT_SUCCESS;
  }

produces the output:

Equal

Classification:

Standard Unix

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

See also:

bcopy(), bzero(), memcmp(), strcmp()


[Previous] [Contents] [Next]