int memcmp ( const void * buffer1, const void * buffer2, size_t num );
Compare two buffers.
Compares the fisrt num bytes of two memory blocks pointed by buffer1 and buffer2.
Returns a value indicating the relationship between the buffers:
For comparative purposes, each byte is considered as unsigned char.
return value description <0 buffer1 is less than buffer2 0 buffer1 is the same as buffer2 >0 buffer1 is greater than buffer2
Defined in ANSI-C.
/* memcmp example */
int n, len1, len2;
printf ("Enter a sentence: "); gets(str1);
printf ("Enter another sentence: "); gets(str2);
n=memcmp ( str1, str2, len1>len2?len1:len2 );
if (n>0) printf ("'%s' is greater than '%s'",str1,str2);
else if (n<0) printf ("'%s' is less than '%s'",str1,str2);
else printf ("'%s' is the same as '%s'\n",str1,str2);
Enter a sentence: 12345
Enter another sentence: 54321
'12345' is less than '54321'
memchr, memcpy, memset, strncmp