uint8 a=9;
uint32 b=0x12345678;
uint32 c=0x87654321;
uint8 d[2][9];
问一下怎么把a,b,c存入二位数组d中?最好用memcpy
下面本人写的,实现不了。
uint8 aa=9;
uint32 bb=0x12345678;
uint32 cc=0x87654321;
uint8 dd[2][9];
dd[2][0]=aa;
memcpy(&dd[2][1],&bb,4);
memcpy(&dd[2][5],&cc,4);
uint32 b=0x12345678;
uint32 c=0x87654321;
uint8 d[2][9];
问一下怎么把a,b,c存入二位数组d中?最好用memcpy
下面本人写的,实现不了。
uint8 aa=9;
uint32 bb=0x12345678;
uint32 cc=0x87654321;
uint8 dd[2][9];
dd[2][0]=aa;
memcpy(&dd[2][1],&bb,4);
memcpy(&dd[2][5],&cc,4);
i=0;
for(i=0;i<9;i++)
printf(“%d–%x\n”,i,dd[2][i]);
解决方案
30
uint8 dd[2][9]; //这里定义 dd[2] 实际只能用 dd[0] 和 dd[1] dd[0][0]=aa; memcpy(&dd[0][1],&bb,4); memcpy(&dd[0][5],&cc,4); for(i=0;i<9;i++) printf("%d--%x\n",i,dd[0][i]);
30
uint8_t aa = 9;
uint32_t bb = 0x12345678;
uint32_t cc = 0x87654321;
uint8_t dd[2][9];
dd[0][0] = aa;
memcpy(&dd[0][1], &bb, sizeof(bb));
memcpy(&dd[0][5], &cc, sizeof(cc));
int i;
for(i=0;i<9;i++)
printf(“%d–%x\n”, i, dd[0][i]);
uint32_t bb = 0x12345678;
uint32_t cc = 0x87654321;
uint8_t dd[2][9];
dd[0][0] = aa;
memcpy(&dd[0][1], &bb, sizeof(bb));
memcpy(&dd[0][5], &cc, sizeof(cc));
int i;
for(i=0;i<9;i++)
printf(“%d–%x\n”, i, dd[0][i]);