比较前n个字符串函数strncasecmp()

定义函数

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

概述

C语言中判断字符串指定长度是否相等的函数,忽略大小写。s1和s2中的所有字母字符在比较之前都转换为小写。该strncasecmp()函数对空终止字符串进行操作。函数的字符串参数应包含一个(’\0’)标记字符串结尾的空字符。

头文件

#include<string.h>

返回值

意义
小于0s1 小于s2
0s1 等于s2
大于0s1大于s2

例子

#include<string.h>
#include<stdio.h>

void compareLengthOfStr(char const *a, char const* b, size_t n)
{
    int flag = strncasecmp(a, b, n);

    if (!flag)
    {
      printf("the length of a equals length of b.\n");
    }
    else if (flag > 0) 
    {
      printf("the length of a is greater.\n");
    }
    else 
    {
        printf("the length of b is greater.\n");
    }
}

int main()
{
    char const *a = "adjhiogP";
    char const *b = "adjHIOG";
    char const *c = "whieHIOUIHF";

    compareLengthOfStr(a, b, 7);
    compareLengthOfStr(a, c,);

    return 0;
}

输出结果

the length of a equals length of b.
the length of b is greater.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值