zoukankan      html  css  js  c++  java
  • 字符串操作函数的几个基本函数

    //---------------------------------------------------------------------------
    int strlen (const char *s)
    {
        const char *sc;
    
        for (sc = s; *sc != '\0'; ++sc)
        {
        }
        return sc - s;
    }
    
    //---------------------------------------------------------------------------
    
    //---------------------------------------------------------------------------
    int strcmp (const char *cs, const char *ct)
    {
        signed char __res;
    
        while (1)
        {
            if ((__res = *cs - *ct++) != 0 || !*cs++)
                break;
        }
        return __res;
    }
    
    //---------------------------------------------------------------------------
    
    //---------------------------------------------------------------------------
    int strncmp (const char *cs, const char *ct, int count)
    {
        signed char __res = 0;
    
        while (count) 
        {
            //dbg_print("*cs = %c, *ct = %c, count = %d\n", *cs, *ct, count);
            if ((__res = *cs - *ct++) != 0 || !*cs++)
                break;
            count--;
        }
        return __res;
    }
    
    //---------------------------------------------------------------------------
    
    //---------------------------------------------------------------------------
    void * memset (void *s, int c, int count)
    {
        char *xs = s;
    
        while (count--)
            *xs++ = c;
        return s;
    }
    
    //---------------------------------------------------------------------------
    
    //---------------------------------------------------------------------------
    void * memcpy (void *dest, const void *src, int count)
    {
        char *tmp = dest;
        const char *s = src;
    
        while (count--)
            *tmp++ = *s++;
        return dest;
    }
    
    //---------------------------------------------------------------------------
    
    //---------------------------------------------------------------------------
    int memcmp (const void *cs, const void *ct, int count)
    {
        const unsigned char *su1, *su2;
        int res = 0;
    
        for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
            if ((res = *su1 - *su2) != 0)
                break;
        return res;
    }
    
    //---------------------------------------------------------------------------
    

  • 相关阅读:
    Netty简单聊天室
    JDK环境变量配置
    EasyUI Tabs
    NIO(五)
    NIO(四)
    银行对公业务和对私业务
    mysql常用操作
    LInux安装MySQL5.7.24详情
    Python3 SMTP发送邮件
    linux下sendmail邮件系统安装详情
  • 原文地址:https://www.cnblogs.com/yuzaipiaofei/p/4124242.html
Copyright © 2011-2022 走看看