使用memcpy 复制unsigned int 型的数据

转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/53214692

函数原型:

void *memcpy(void *dest, const void *src, size_t n);

之前使用memcpy复制的都是unsigned char型的数据,最近突发奇想,想memcpy来复制unsigned int 型的数据。

下面就是我写的  用于验证memcpy复制unsigned int 型数据 的代码。

#include<string.h>
#include<stdio.h>

unsigned int flash_read(unsigned int *address,unsigned int *buf,unsigned int len)
{
	unsigned int i;
	if(buf==NULL)
		return 1;
	for(i=0;i<len;i++){
		*buf =*address;
		address+=4;
	}
	return 0;
}

int main(int argc,char *argv[])
{
        int i;
        unsigned int ceshi[]={1234,4321,5678,8765,6789,9876};
        unsigned int ceshiPrint[20];

        memcpy(ceshiPrint,ceshi,sizeof(ceshi));
        for(i=0;i<6;i++){
                printf("memcpy %d\n",ceshiPrint[i]);
        }

        flash_read(ceshiPrint,ceshi,6);
        for(i=0;i<6;i++){
                printf("flash_read %d\n",ceshiPrint[i]);
        }

        return 0;
}

运行结果:

book@ubuntu:/home/linux_c/thread$ ./memcpy 
memcpy 1234
memcpy 4321
memcpy 5678
memcpy 8765
memcpy 6789
memcpy 9876
flash_read 1234
flash_read 4321
flash_read 5678
flash_read 8765
flash_read 6789
flash_read 9876

posted @ 2016-11-18 11:47  隔壁王叔叔a  阅读(416)  评论(0编辑  收藏  举报