memicmp() — Compare Bytes
Format
#include <string.h> // also in <memory.h>
int memicmp(void *buf1, void *buf2, unsigned int cnt);
Note: The
memicmp
function is available
for C++ programs. It is available for C only when the program defines
the __cplusplus__strings__ macro.Language Level
Extension
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE category of the current locale. For more information, see Understanding CCSIDs and Locales.
Description
The memicmp
function
compares the first cnt bytes of buf1 and buf2 without
regard to the case of letters in the two buffers. The function converts
all uppercase characters into lowercase and then performs the comparison.
Return Value
The return
value of memicmp
indicates the result as follows:
Value | Meaning |
---|---|
Less than 0 | buf1 less than buf2 |
0 | buf1 identical to buf2 |
Greater than 0 | buf1 greater than buf2 |
Example
This example copies two strings
that each contain a substring of 29 characters that are the same except
for case. The example then compares the first 29 bytes without regard
to case.
#include <stdio.h>
#include <string.h>
char first[100],second[100];
int main(void)
{
int result;
strcpy(first, "Those Who Will Not Learn From History");
strcpy(second, "THOSE WHO WILL NOT LEARN FROM their mistakes");
printf("Comparing the first 29 characters of two strings.\n");
result = memicmp(first, second, 29);
printf("The first 29 characters of String 1 are ");
if (result < 0)
printf("less than String 2.\n");
else
if (0 == result)
printf("equal to String 2.\n");
else
printf("greater than String 2.\n");
return 0;
}
The output should be: Comparing the first 29 characters of two strings.
The first 29 characters of String 1 are equal to String 2
Related Information
- memchr() — Search Buffer
- memcmp() — Compare Buffers
- memcpy() — Copy Bytes
- memmove() — Copy Bytes
- memset() — Set Bytes to Value
- strcmp() — Compare Strings
- strcmpi() — Compare Strings Without Case Sensitivity
- stricmp() — Compare Strings without Case Sensitivity
- strnicmp() — Compare Substrings Without Case Sensitivity
- <string.h>