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;
    }
    
    //---------------------------------------------------------------------------
    

  • 相关阅读:
    Perl的运算符号字符
    windows xp 使用远程桌面时的关机/重新启动方法
    抵御TCP的洪水
    远程桌面连接中的常见问题 连接上就断开
    批量kill mysql进程
    Linux如何查看硬盘型号和缓存
    Apache Rewrite 规则详解
    nginx 内置变量大全
    大数据量分页存储过程效率测试附代码
    ASP.Net 更新页面输出缓存的几种方法(包括用户控件,iframe,页面缓存等)
  • 原文地址:https://www.cnblogs.com/yuzaipiaofei/p/4124242.html
Copyright © 2011-2022 走看看