hello head

char* strcpy_s(char* dest, unsigned int size, char* src)
{
    if (NULL == dest || NULL == src || 0 == size)
    {
        return NULL;
    }
    char* p = dest;
    char* q = src;
    int srcSize = 0;
    while (*(q++))
    {
        ++srcSize;
    }
    if (size - 1 < srcSize)//源比目标长
    {
        return NULL;
    }
    q = src;
    while (*q)
    {
        *(p++) = *(q++);
    }
    *p = '\0';
    return dest;
}
int strcmp_s(char* str1, char* str2)
{
    if (NULL == str1 && NULL == str2)return 0;
    if (NULL == str1)return -1;
    if (NULL == str2)return 1;
    while(1)
    {
        if (*str1 == *str2)
        {
            if(0 == *str1)
            {
                return 0;
            }
            str1++;
            str2++;
        }
        else
        {
            return *str1 - *str2;
        }
    }
}

 

posted on 2017-08-28 12:27  gardonkoo  阅读(192)  评论(0编辑  收藏  举报

hello foot