想请问的完整程式码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ARRAYSIZE 10
int main()
{
int i;
unsigned long buff;
unsigned char *ReadBuf = NULL;
ReadBuf = (unsigned char *)malloc(sizeof(unsigned char)*ARRAYSIZE);
memset(ReadBuf, '1', ARRAYSIZE);
for(i=0; i<ARRAYSIZE; i++)
{
printf("%c ", ReadBuf[i]);
}
printf("\n");
unsigned char *temp=
(unsigned char *)malloc(sizeof(unsigned char)*ARRAYSIZE);
memcpy((void *)temp, (void *)buff, ARRAYSIZE);
buff = (unsigned long)temp;
memcpy((void *)buff, (void *)ReadBuf, ARRAYSIZE);
//how to print the buff??
for(i=0; i<ARRAYSIZE; i++)
{
printf("%lu ", *(&buff+i));
}
printf("\n");
return 0;
}
问题:
因为buff是unsigned long,所以我用%lu去印,
但因出的都不是正确的内容:
1 1 1 1 1 1 1 1 1 1
想请问哪里有问题,谢谢!