C language itself implement memory copy function Memmov ()

Source: Internet
Author: User
Tags assert

Tag: c; memory copy function

/************************************************************************************1. Simulation implements the implementation of the Memmove function. (consider memory overlap) ************************************************************************************/#include < stdio.h> #include <string.h> #include <assert.h>void * my_memmove (void *aim,const  void *source,int length) {Int i = 0;void *p = aim;assert (aim& &source);if  (((char*) aim -  (char*) source)//memory overlap from back to forward copy  >= 0 ({for   length-1; i >=0; i--) {* ((char *) aim + i*sizeof (char))  = * (( char *) source + i*sizeof (char));} return  (P);} else     //non-overlapping   normal copy {for  (i = 0; i <length; i++) {* ((char *) aim + i*sizeof (char))  = * ((char *) source + i*sizeof (char));} return  (P);}}  //  1 2 3 4 5&nbSp;6 7 8 9 0 0 // *0*1*2*3*4*5*6*7*8*9*10 //1 2 3 4  5 6 7 8 9 0 0int main () {int arr[11] = { 1, 2 ,  3, 4, 5, 6, 7, 8, 9, 0 };int i = 0;my_memmove ( arr, arr , 36);for  (i; i < 11; i++) printf ("%d\n", Arr[i]);/*for   (i = 0; i < 10;i++)     printf ("%d\n", * (  (int * ) My_memmove (arr,  arr+1,  36) +1); */return 0;}


C language itself implement memory copy function Memmov ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.