C库函数 strncasecmp

2021-07-24, updated 2021-09-12

1
2
3
#include <string.h>

int strncasecmp(const char *s1, const char *s2, size_t n);

函数说明:strncasecmp()用来比较参数s1 和s2 字符串前n个字符,比较时会自动忽略大小写的差异。

返回值:若参数s1 和s2 字符串相同则返回0。s1 若大于s2 则返回大于0 的值,s1 若小于s2 则返回小于0 的值。

范例

1
2
3
4
5
6
7
#include <string.h>
main(){
    char *a = "aBcDeF";
    char *b = "AbCdEf";
    if(!strncasecmp(a, b, 3))
    printf("%s =%s\n", a, b);
}

执行结果:

1
aBcDef=AbCdEf
words: 156 tags: C