Parameters
- ptr1
- Pointer to block of memory.
- ptr2
- Pointer to block of memory.
- num
- Number of bytes to compare.
Return Value
Returns an integral value indicating the relationship between the content of the memory blocks:A zero value indicates that the contents of both memory blocks are equal.
A value greater than zero indicates that the first byte that does not match in both memory blocks has a greater value in ptr1 than in ptr2 as if evaluated as unsigned char values; And a value less than zero indicates the opposite.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Output:
Enter a sentence: building Enter another sentence: book 'building' is greater than 'book'. |
building is greater than book because the first non-matching character in both words are 'u' and 'o' respectively, and 'u' (117) evaluates as greater than 'o' (111).
See also
| memchr | Locate character in block of memory (function) |
| memcpy | Copy block of memory (function) |
| memset | Fill block of memory (function) |
| strncmp | Compare characters of two strings (function) |
