|
|
coherent
memcmp() String Function memcmp()
Compare two regions
#include <string.h>
iinntt mmeemmccmmpp(_r_e_g_i_o_n_1, _r_e_g_i_o_n_2, _c_o_u_n_t);
cchhaarr *_r_e_g_i_o_n_1; cchhaarr *_r_e_g_i_o_n_2; uunnssiiggnneedd iinntt _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
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.