• 字符串操作函数的几个基本函数


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

  • 相关阅读:
    Vue.js组件理解
    Vue.js 基础知识
    JS-WEB-API 整理
    JS面向对象基础
    JS基础知识系统整理(不断更新)
    图解关于pageX,pageY,screenX,screenY,clientX,clientY的区别
    妙味JS学习记录(二)
    Ajax全接触笔记
    妙味JS学习记录(一)
    c#设计模式系列:状态模式(State pattern)
  • 原文地址:https://www.cnblogs.com/yuzaipiaofei/p/4124242.html
Copyright © 2020-2023  润新知