

memcmp()                 String Function                 memcmp()




Compare two regions

#include <string.h>
iinntt mmeemmccmmpp(_r_e_g_i_o_n_1, _r_e_g_i_o_n_2, _c_o_u_n_t);
cchhaarr *_r_e_g_i_o_n_1; cchhaarr *_r_e_g_i_o_n_2; uunnssiiggnneedd iinntt _c_o_u_n_t;

memcmp compares  region1 with region2 character  by character for
count characters.

If every  character in region1 is  identical to its corresponding
character in region2, then memcmp returns zero.  If it finds that
a character  in region1 has a numeric value  greater than that of
the corresponding character  in region2, then it returns a number
greater than zero.  If it finds that a character in region1 has a
numeric value less  than less that of the corresponding character
in region2, then it returns a number less than zero.

For example, consider the following code:


        char region1[13], region2[13];
        strcpy(region1, "Hello, world");
        strcpy(region2, "Hello, World");
        memcmp(region1, region2, 12);


memcmp  scans  through  the  two  regions  of  memory,  comparing
region1[0] with  region2[0], and so  on, until it  finds two cor-
responding ``slots'' in the arrays whose contents differ.  In the
above example, this will occur when it compares region1[7] (which
contains `w') with region2[7] (which contains `W').  It then com-
pares the two letters to  see which stands first in the character
table used  in this  implementation, and returns  the appropriate
value.

memcmp  differs from  the string comparison  routine strcmp  in a
number of ways.   First, memcmp compares regions of memory rather
than strings;  therefore, it does  not stop when  it encounters a
null character.

Also, memcmp can be used to  compare an int array with a char ar-
ray is permissible because memcmp simply compares areas of data.

***** See Also *****

strcmp(), string functions, string.h










COHERENT Lexicon                                           Page 1


