[C语言] 达成strcmp

By admin in Python on 2019年8月24日

[C语言] 实现strcmp

#include <stdio.h>
#include <assert.h>

int my_strcmp(const char * str1, char * str2)      
{
    int ret = 0;
    assert(str1);
    assert(str2);
    while ((*str1 == *str2) && *str1&&*str2)
    {
        str1++;
        str2++;
    while (!(*str1&&*str2))  //判断str1和str是否同时指向 \0
         return 1;       //相等返回1
    }
    return -1;           //不相等返回-1
}

void main()
{
       char str1[100] = {"i love"};
       char str2[50] = {"China "};
       printf("%d\n",my_strcmp(str1,str2));
}

 

http://www.bkjia.com/Cyy/1071724.htmlwww.bkjia.comtruehttp://www.bkjia.com/Cyy/1071724.htmlTechArticle\[C语言\] 实现strcmp #include stdio.h#include
assert.h int my_strcmp(const char * str1, char * str2) { int ret = 0;
assert(str1); assert(str2); while ((*str1 == *str2)
*str1*str2…

C语言:模拟完结strcmp

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

void *my_memmove(void *p1, void *p2, size_t count)
{
    assert(p1);
    assert(p2);
    char *dest = (char *)p1;
    char *src = (char *)p2;
    dest = dest + 16;
    src = src + 8;
    if ((src < dest) && (dest < src + count))
    {
        while (count--)
        {
            *(dest + count) = *(src + count);
        }
    }
    else
    {
        while (count--)
        {
            *dest = *src;
            src++;
            dest++;
        }
    }
    return p2;
}

int main()
{
    int arr1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    int i = 0;
    int len = sizeof(arr1) / sizeof(arr1[0]);
    int *ret = my_memmove(arr1, arr1, 16);
    for (i = 0; i < len; i++)
    {
        printf("%d ", *(ret + i));
    }
    system("pause");
    return 0;
}

 

http://www.bkjia.com/Cyy/1073417.htmlwww.bkjia.comtruehttp://www.bkjia.com/Cyy/1073417.htmlTechArticleC语言:模拟实现strcmp #define
_CRT_SECURE_NO_WARNINGS
1#includestdio.h#includestdlib.h#includeassert.h void
*my_memmove(void *p1, void *p2, size_t count){ assert(p1);
assert…

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 韦德国际手机网站 版权所有