|
|
1.1 ! root 1: ! 2: ! 3: memcmp() String Function memcmp() ! 4: ! 5: ! 6: ! 7: ! 8: Compare two regions ! 9: ! 10: #include <string.h> ! 11: iinntt mmeemmccmmpp(_r_e_g_i_o_n_1, _r_e_g_i_o_n_2, _c_o_u_n_t); ! 12: cchhaarr *_r_e_g_i_o_n_1; cchhaarr *_r_e_g_i_o_n_2; uunnssiiggnneedd iinntt _c_o_u_n_t; ! 13: ! 14: memcmp compares region1 with region2 character by character for ! 15: count characters. ! 16: ! 17: If every character in region1 is identical to its corresponding ! 18: character in region2, then memcmp returns zero. If it finds that ! 19: a character in region1 has a numeric value greater than that of ! 20: the corresponding character in region2, then it returns a number ! 21: greater than zero. If it finds that a character in region1 has a ! 22: numeric value less than less that of the corresponding character ! 23: in region2, then it returns a number less than zero. ! 24: ! 25: For example, consider the following code: ! 26: ! 27: ! 28: char region1[13], region2[13]; ! 29: strcpy(region1, "Hello, world"); ! 30: strcpy(region2, "Hello, World"); ! 31: memcmp(region1, region2, 12); ! 32: ! 33: ! 34: memcmp scans through the two regions of memory, comparing ! 35: region1[0] with region2[0], and so on, until it finds two cor- ! 36: responding ``slots'' in the arrays whose contents differ. In the ! 37: above example, this will occur when it compares region1[7] (which ! 38: contains `w') with region2[7] (which contains `W'). It then com- ! 39: pares the two letters to see which stands first in the character ! 40: table used in this implementation, and returns the appropriate ! 41: value. ! 42: ! 43: memcmp differs from the string comparison routine strcmp in a ! 44: number of ways. First, memcmp compares regions of memory rather ! 45: than strings; therefore, it does not stop when it encounters a ! 46: null character. ! 47: ! 48: Also, memcmp can be used to compare an int array with a char ar- ! 49: ray is permissible because memcmp simply compares areas of data. ! 50: ! 51: ***** See Also ***** ! 52: ! 53: strcmp(), string functions, string.h ! 54: ! 55: ! 56: ! 57: ! 58: ! 59: ! 60: ! 61: ! 62: ! 63: ! 64: COHERENT Lexicon Page 1 ! 65: ! 66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.