用法:#include <string.h>
功能:比较内存区域buf1和buf2的前count个字节但不区分字母的大小写。
说明:memicmp同memcmp的唯一区别是memicmp不区分大小写字母。
当buf1<buf2时,返回值<0
当buf1=buf2时,返回值=0
当buf1>buf2时,返回值>0
int _memicmp( const void *buf1, const void *buf2, size_t count ); int _memicmp_l( const void *buf1, const void *buf2, size_t count, _locale_t locale );
参数
buf1
第一个缓冲区。
buf2
第二个缓冲区。
count
字符数。
locale
要使用的区域设置。
返回值指示在缓冲区之间的关系。
返回值 | buf1 和 buf2 的第一个计数字节的关系 |
---|---|
< 0 | buf1 小于 buf2 。 |
0 | buf1 等于 buf2 。 |
> 0 | buf1 大于buf2 。 |
_NLSCMPERROR | 出现了错误。 |
如果任一buf1
或buf2
是 null 指针,此函数将调用无效参数处理程序中,如中所述参行数验证。 如果允许继续执,则函数将返回 _NLSCMPERROR
,并且将 errno
设置为 EINVAL
。
_memicmp
将当前区域设置用于与区域设置相关的行为;_memicmp_l
也是一样,只不过它使用传入的区域设置。 有关详细信息,请参阅 Locale。
例程 | 必需的标头 |
---|---|
_memicmp | <memory.h> 或 <string.h> |
_memicmp_l | <memory.h> 或 <string.h> |
有关更多兼容性信息,请参阅“简介”中的 Compatibility 。
// crt_memicmp.c // This program uses _memicmp to compare // the first 29 letters of the strings named first and // second without regard to the case of the letters. #include <memory.h> #include <stdio.h> #include <string.h> int main( void ) { int result; char first[] = "Those Who Will Not Learn from History"; char second[] = "THOSE WHO WILL NOT LEARN FROM their mistakes"; // Note that the 29th character is right here ^ printf( "Compare '%.29s' to '%.29s'\n", first, second ); result = _memicmp( first, second, 29 ); if( result < 0 ) printf( "First is less than second.\n" ); else if( result == 0 ) printf( "First is equal to second.\n" ); else if( result > 0 ) printf( "First is greater than second.\n" ); }
Compare 'Those Who Will Not Learn from' to 'THOSE WHO WILL NOT LEARN FROM' First is equal to second.