.TH "memcmp()" "" "" "String Function (libc)"
.PC "Compare two regions"
.B "#include <string.h>"
\fBint memcmp(\fIregion1\^\fB, \fIregion2\^\fB, \fIcount\^\fB)\fR
\fBchar *\fIregion1\^\fB; char *\fIregion2\^\fB; unsigned int \fIcount\^\fB;\fR
.PP
.II "regions, compare"
.II "compare two regions"
.B memcmp()
compares
.I region1
with
.I region2
character by character for
.I count
characters.
.PP
If every character in
.I region1
is identical to its corresponding character in
.IR region2 ,
then
.B memcmp()
returns zero.
If it finds that a character in
.I region1
has a numeric value greater than that of the corresponding character in
.IR region2 ,
then it returns a number greater than zero.
If it finds that a character in
.I region1
has a numeric value less than less that of the corresponding character in
.IR region2 ,
then it returns a number less than zero.
.PP
For example, consider the following code:
.DM
	char region1[13], region2[13];
	strcpy(region1, "Hello, world");
	strcpy(region2, "Hello, World");
	memcmp(region1, region2, 12);
.DE
.PP
.B memcmp()
scans through the two regions of memory, comparing
.B region1[0]
with
.BR region2[0] ,
and so on, until it finds two corresponding \*(QLslots\*(QR in the
arrays whose contents differ.
In the above example, this will occur when it compares
.B region1[7]
(which contains \*(Qlw\*(Qr)
with
.B region2[7]
(which contains \*(QlW\*(Qr).
It then compares the two letters to see which stands first in the
character table used in this implementation, and returns the
appropriate value.
.PP
.B memcmp()
differs from the string comparison routine
.B strcmp()
in a number of ways.
First,
.B memcmp()
compares regions of memory rather than strings;
therefore, it does not stop when it encounters a NUL.
.PP
Also, you can use
.B memcmp()
to compare an
.B int
array with a
.B char
array, because
.B memcmp()
simply compares areas of data.
.SH "See Also"
.Xr "libc," libc
.Xr "strcmp()," strcmp
.Xr "string.h" string.h
.br
\*(AS, \(sc7.11.4.1
