Advertisement

学习C标准库memcpy函数源码体会

阅读量:
复制代码
    读 C 标准库 memcpy 函数 源码 感悟
    

在查阅了memcpy源码之后,我编写了一个与之极为相似的函数,完成之后感触良多。

以下为我所编写的代码:

复制代码
 #include <cstring>

    
 void * memcpy_My(void * dst,const void * src,size_t n){
    
 	char * s1 = ( char *)dst;
    
 	const  char * s2 = (const char *)src;
    
 	for (; n > 0; n--,s1++,s2++)
    
 	{
    
 		*s1 = *s2;
    
 	}
    
 	return  dst;
    
 }
    
  
    
 int _tmain(int argc, _TCHAR* argv[])
    
 {
    
 	char a[] = "hello,world";
    
 	char b[] = "xxxxxxxxxxxxxxxxxxxxx";
    
 	memcpy_My((void *) b,(void *) a,strlen(a)+1);
    
 	printf("%s",b);
    
 	return 0;
    
 }

全部评论 (0)

还没有任何评论哟~