zoukankan      html  css  js  c++  java
  • strcmpi,stricmp函数

    函数原型:extern int strcmpi(char *str1,char * str2)

                       或者 extern int stricmp(char *str1,char * str2)

    参数说明:str1为第一个要比较的字符串,str2为第二个要比较的字符串。
            
    所在库名:#include <string.h>
      
    函数功能:比较字符串str1和str2,但是不区分字母的大小写(这点就是与strcmp的区别)。

    返回说明:返回整数值:当str1<str2时,返回值<0; 当str1=str2时,返回值=0; 当str1>str2时,返回值>0。

    其它说明:暂时无。

    实例:

    第一种情形:

    #include <string.h>
    #include 
    <stdio.h>
    int main()
    {
        
    char *str1="SKY2098!";
        
    char *str2="sky2098,I like writing!";   //str1与str2的大小写不一样,而且长度不同

        
    int inttemp;

        inttemp
    =strcmpi(str1,str2);   //将字符串比较的返回值保存在int型变量inttemp中,用strcmpi函数
        if(inttemp<0)
        
    {
            printf(
    "lexicographic(str1) < lexicographic(str2) ");
        }

        
    else if(inttemp>0)
            
    {
                printf(
    "lexicographic(str1) > lexicographic(str2) ");
            }

            
    else
            
    {
                printf(
    "lexicographic(str1) == lexicographic(str2) ");
            }

        
    return 0;
    }

    在VC++ 6.0 编译运行:

    显然当str1与str2比较后,由于str1是str2的子串,故而str2的字典序比str1要大,返回值<0。

    第二种情形:

    #include <string.h>
    #include 
    <stdio.h>
    int main()
    {
        
    char *str1="SKY2098,I liKE wrITing!";
        
    char *str2="sky2098,I like writing!";   //str1与str2的大小写不一样,但是代表的含义一样,也就是str1的字典序与str2相同,不区分大小写
        int inttemp;

        inttemp
    =strcmpi(str1,str2);   //将字符串比较的返回值保存在int型变量inttemp中,用strcmpi函数
        if(inttemp<0)
        
    {
            printf(
    "lexicographic(str1) < lexicographic(str2) ");
        }

        
    else if(inttemp>0)
            
    {
                printf(
    "lexicographic(str1) > lexicographic(str2) ");
            }

            
    else
            
    {
                printf(
    "lexicographic(str1) == lexicographic(str2) ");
            }

        
    return 0;
    }

    在VC++ 6.0 编译运行:

  • 相关阅读:
    JavaScript入门基础(三)
    JavaScript入门基础(二)
    Web页面该如何布局
    如何通过SQL创建删除表的索引,UNIQUE KEY
    vim使用大全
    安装vmwaretools后 真机和虚拟机仍不能复制黏贴
    php通用函数html时间文件大小生成随机数
    Centos下安装配置phpmyadmin
    [Leetcode 43] 11 Container With Most Water
    [Leetcode 39] 129 Sum Root to Leaf Numbers
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/5835373.html
Copyright © 2011-2022 走看看