Format
#include <string.h> // also in <memory.h>
int memicmp(void *buf1, void *buf2, unsigned int cnt);
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:
Example that uses memicmp()
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: