zoukankan      html  css  js  c++  java
  • strcasecmp函数和strncasecmp函数原型

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

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

    [cpp] view plain copy
     
    1. #include <stdio.h>  
    2. #include <string.h>  
    3. #include <ctype.h>  
    4. int strcasecmp(const char *s1, const char *s2)  
    5. {  
    6.     int c1, c2;  
    7.     do {  
    8.         c1 = tolower(*s1++);  
    9.         c2 = tolower(*s2++);  
    10.     } while(c1 == c2 && c1 != 0);  
    11.     return c1 - c2;  
    12. }  
    13. int main(void)  
    14. {  
    15.     int n = 4;  
    16.     char str1[] = "Acef";  
    17.     char str2[] = "ACEFd";  
    18.     printf("strcasecmp(str1, str2) = %d/n", strcasecmp(str1, str2));  
    19.     return 0;  
    20. }  

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

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

    [c-sharp] view plain copy
     
    1. #include <stdio.h>  
    2. #include <string.h>  
    3. #include <ctype.h>  
    4.   
    5. int mystrncasecmp(const char *s1, const char *s2, int n)  
    6. {  
    7.     int c1, c2;  
    8.     do {  
    9.         c1 = tolower(*s1++);  
    10.         c2 = tolower(*s2++);  
    11.     } while((--n > 0) && c1 == c2 && c1 != 0);  
    12.     return c1 - c2;  
    13. }  
    14. int main(void)  
    15. {  
    16.     int n = 4;  
    17.     char str3[] = "ABCf";  
    18.     char str4[] = "abcd";  
    19.     printf("mystrncasecmp(str3, str4, n) = %d/n", mystrncasecmp(str3, str4, n));  
    20.     return 0;  
    21. }  
  • 相关阅读:
    内聚和耦合的举例
    OneZero第四周第五次站立会议(2016.4.15)
    OneZero第四周第四次站立会议(2016.4.14)
    OneZero团队Beta发布剧透
    PSP(4.6——4.12)以及周记录
    关于“内聚和耦合”
    CSV 注入实战
    BurpSuite 一些小技巧
    博客园URL跳转钓鱼
    【Demo 0005】Android 资源
  • 原文地址:https://www.cnblogs.com/-colin/p/8520960.html
Copyright © 2011-2022 走看看