zoukankan      html  css  js  c++  java
  • 不区分大小写字符串比较函数

    #include "ctype.h"

    int strnicmp(char *s1, char __code *s2,  int len)
    {
        unsigned char c1, c2;
        if(!len)
            return 0;
        do{
            c1 = *s1++;
            c2 = *s2++;
            if (!c1 || !c2)
                break;
            if (c1 == c2)
                continue;
            c1 = tolower(c1);
            c2 = tolower(c2);
            if (c1 != c2)
                break;
        }while(--len);
        return (int)c1 - (int)c2;
    }

    以上需要使用C语言自带的库文件ctype.h才能使用,当单片机内存比较紧张的时候建议不要使用自带的库文件。另外一种写法见评论。

  • 相关阅读:
    hdu3874
    spoj D-query
    hdu4348
    hdu4417
    hdu2665
    [LUOGU] P1057 传球游戏
    [CODEVS] 2193 数字三角形WW
    [CODEVS] 2189 数字三角形W
    [模板] 线段树
    [模板] 树状数组
  • 原文地址:https://www.cnblogs.com/zengxy/p/8818097.html
Copyright © 2011-2022 走看看