Побайтово сравнить две области памяти
#include <string.h>int memcmp( const void *s1,const void *s2,size_t length );
libc
The memcmp() function compares length bytes of the buffer pointed to by s1 to the buffer pointed to by s2.
#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" );} elseif ( retval == 0 ){printf( "Equal to\n" );} else {printf( "Greater than\n" );}return (EXIT_SUCCESS);}
Код генерирует следующий вывод:
$ ./a.out Less than
ANSI, POSIX 1003.1
memccpy(), memchr(), memcpy(), memicmp(), memmove(), memset()
Предыдущий раздел: Описание API системной библиотеки