欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C语言:模拟实现strcmp

程序员文章站 2022-11-18 09:31:11
#define _CRT_SECURE_NO_WARNINGS 1 #include #include #i...
#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;
}