strnicmp()函数使用方法

strnicmp

 
  函数名: strnicmp
 
  功 能: 比较字符串str1和str2的前n个字符串字典序的大小,但是不区分字母大小写。
 
  比较是这样进行的,先比较2个字符串的第1个字符字典序的大小,如果能比较出大小,则马上返回了,如果不能区别大小,开始比较第2个,如果这时第1个字符串已经到尽头了,第2个字符串还有字符,这时算第2个字符串大。例:
 
  char *str1="B";
 
  char *str2="abcD";
 
  int n=4;
 
  strnicmp(char *str1, char *str2, 4);
 
  结果是str1大,因为B在a的后面。
 
  char *str1="ABCD";
 
  char *str2="abcD";
 
  int n=4;
 
  strnicmp(char *str1, char *str2, 4);
 
  结果一样大。
 
  char *str1="abc";
 
  char *str2="abcD";
 
  int n=5;
 
  strnicmp(char *str1, char *str2, 5);
 
  结果是str2大。
 
  可以把上述数据,填到下面程序中一试便知道。
 
  用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
 
  程序例:
 
  #include <string.h>
 
  #include <stdio.h>
 
  int main(void)
 
  {
 
  char *buf1 = "BBBccc", *buf2 = "bbbccc";
 
  int ptr;
 
  ptr = strnicmp(buf2, buf1, 3);
 
  if (ptr > 0)
 
  printf("buffer 2 is greater than buffer 1\n");
 
  if (ptr < 0)
 
  printf("buffer 2 is less than buffer 1\n");
 
  if (ptr == 0)
 
  printf("buffer 2 equals buffer 1\n");
 
  return 0;
 
  }

转载于:https://www.cnblogs.com/jawn/articles/2543440.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值