memicmp ()- 比较字节
格式
#include <string.h> // also in <memory.h>
int memicmp(void *buf1, void *buf2, unsigned int cnt);注:
memicmp 函数可用于 C++ 程序。 仅当程序定义 __cplusplus__strings__ 宏时,它才可用于 C。语言级别
分机
线程安全
是
语言环境敏感
此函数的行为可能受当前语言环境的 LC_CTYPE 类别影响。 有关更多信息,请参阅 了解 CCSID 和语言环境。
描述
memicmp 函数将 buf1 和 buf2 的前 cnt 字节进行比较,而不考虑两个缓冲区中的字母大小写。 该函数将所有大写字符转换为小写,然后执行比较。
返回值
返回值 memicmp 指示结果,如下所示:
| 值 | 含义 |
|---|---|
| 小于 0 | buf1 小于 buf2 |
| 0 | buf1 与 buf2 完全相同 |
| 大于 0 | buf1 大于 buf2 |
示例
此示例复制两个字符串,每个字符串都包含 29 个字符的子串,但大小写除外。 然后,该示例将前 29 个字节进行比较,而不考虑大小写。
#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;
}输出应该为:Comparing the first 29 characters of two strings.
The first 29 characters of String 1 are equal to String 2