bcopy()—— 拷贝内存内容

bcopy()函数

    原型:void bcopy(const  void  *src,  void  *dest,  int  n)

    用法:#include <string.h>

    功能:将字符串src的前n个字节复制到dest中。

    说明:bcopy()函数与memcpy()函数一样都是用来拷贝src所指的内存内容前n个字节到dest所指的地址不过参数src与dest在传给

函数时,是相反的位置;bcopy()函数不检查字符串中的空字节NULL,并且函数没有返回值,所以建议使用memcpy()函数代替。

    举例:

#include <string.h>
#include <stdio.h>
main()
{
	char dest[30]="string(a)";
	char src[30]="string_1   string_2";
	int i;
	
	bcopy(src,dest,30);		/* src指针放在前*/
	printf("bcopy():%s\n",dest);
	for(i=0;i<30;i++)
		printf("%c",dest[i]);
	
	memcpy(dest,src,30); 		/*dest指针放在前*/
	printf("\nmemcpy():%s\n",dest);
	for(i=0;i<30;i++)
		printf("%c",dest[i]);
	
	printf("\n");
	
	return 0;
}


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值