function
<cstring>
memcmpint memcmp ( const void * ptr1, const void * ptr2, size_t num );
Compare two blocks of memory
Compares the first num bytes of the block of memory pointed by ptr1 to the first num bytes pointed by ptr2, returning zero if they all match or a value different from zero representing which is greater if they do not.Notice that, unlike strcmp, the function does not stop comparing after finding a null character.
<0
the first byte that does not match in both memory blocks has a lower value in ptr1 than in ptr2 (if evaluated as unsigned char values) 0
the contents of both memory blocks are equal >0
the first byte that does not match in both memory blocks has a greater value in ptr1 than in ptr2 (if evaluated as unsigned char values)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* memcmp example */
#include <stdio.h>
#include <string.h>
int main ()
{
char buffer1[] = "DWgaOtP12df0";
char buffer2[] = "DWGAOTP12DF0";
int n;
n=memcmp ( buffer1, buffer2, sizeof(buffer1) );
if (n>0) printf ("'%s' is greater than '%s'.\n",buffer1,buffer2);
else if (n<0) printf ("'%s' is less than '%s'.\n",buffer1,buffer2);
else printf ("'%s' is the same as '%s'.\n",buffer1,buffer2);
return 0;
}
'DWgaOtP12df0' is greater than 'DWGAOTP12DF0'.
DWgAOtp12Df0 is greater than DWGAOTP12DF0 because the first non-matching character in both words are 'g' and 'G' respectively, and 'g' (103) evaluates as greater than 'G' (71).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4