Header File
mem.h, string.h
Category
Memory and String Manipulation Routines, Inline Routines
Prototype
int memcmp(const void *s1, const void *s2, size_t n);
Description
Compares two blocks for a length of exactly n bytes.
memcmp is available on UNIX System V systems.
memcmp compares the first n bytes of the blocks s1 and s2 as unsigned chars.
Return Value
Because it compares bytes as unsigned chars, memcmp returns a value that is
memcmp(“\xFF”, “\x7F”, 1)
returns a value greater than 0.
#include <stdio.h> #include <string.h> int main(void) { char *buf1 = "aaa"; char *buf2 = "bbb"; char *buf3 = "ccc"; int stat; stat = memcmp(buf2, buf1, strlen(buf2)); if (stat > 0) printf("buffer 2 is greater than buffer 1\n"); else printf("buffer 2 is less than buffer 1\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; }
Portability
POSIX |
Win32 |
ANSI C |
ANSI C++ |
+ |
+ |
+ |
+ |
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|