memcmp, _fmemcmp
raw OCR
Compares two blocks for a length of exactly n bytes.
Defined in header <mem.h>
Syntax
#include <mem.h>
Near version: int memcmp(const void *sl, const void *s2, sizet n);
Far version: int far _fmemcmp(const void far *sl, const void far *s2,
size_t n)
Portability
| DOS | UNIX | Windows | ANSI C | C++ only | |
|---|---|---|---|---|---|
| Near version | ■ | ■ | ■ | ■ | |
| Far version | ■ | ■ |
Remarks
memcmp is available on UNIX System V systems.
memcmp compares the first n bytes of the blocks si and s2 as unsigned chars.
Return value
| Because it compares bytes as unsigned chars, memcmp | returns a value |
< 0 if si is less than s2 = 0 if si is the same as s2 > 0 if si is greater than s2
For example,
memcmp("\xFF", "\x7F", 1) returns a value greater than 0.
See also
Example
#include <stdio.h>
#include <string.h>
int main(void)
char *bufl = "aaa";
char *buf2 = "bbb";
char *buf3 = "ccc";
int Stat;
Stat = memcmp (buf2, bufl, strlen(buf2));
if (Stat > 0)
printf ("buffer 2 is greater than buffer l\n");
else
printf ("buffer 2 is less than buffer l\n");
Stat = memcmp(buf2, buf3, strlen(buf2));
if (Stat > 0)
printf("buffer 2 is greater than buffer 3\n");
else
printf("buffer 2 is less than buffer 3\n");
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `memcmp, Jmemcmp` read as `memcmp, _fmemcmp`
Stable link: /3.1/mem.h/memcmp/
· short form /3.1/memcmp/