问题:
实现memset2() 和bzero2()
v
oid * memset2(void *vp, Byte value, int size)
{
Byte *bp = (Byte *)vp;
int i = 0;
for (i=0; i<size; i++) {
bp[i] = value;
}
return vp;
}
void bzero2(void *vp, int size)
{
memset2(vp, 0x0, size);
}
测试:
int testMemsetAndBzero()
{
char str[10] = {0};
int iarray[10] = {0};
memset2(str, 'a', sizeof(str)-1);
printf("str is:%s\n", str);
memset2(iarray, 0xff, sizeof(iarray));
int i = 0;
for (i=0; i<10; i++) {
printf("iarray[%d] is:%d\n", i, iarray[i]);
}
printf("-----------split line -----------\n");
bzero2(iarray, sizeof(iarray));
for (i=0; i<10; i++) {
printf("iarray[%d] is:%d\n", i, iarray[i]);
}
return 0;
}