Let's say I have this following byte array:
Code:
{0xAB, 0x34, 0x15, 0xFD, 0x76, 0xED};
What I want is to have a new array which consists of:
Code:
{0x34, 0x15, 0xFD, 0x76}
This code works as expected (tested using MSVC 2015 update 3):
Code:
#include <stdio.h>
#include <string.h>
typedef unsigned char BYTE;
void dump(BYTE*);
int main(void){
BYTE src[6] = {0xAB, 0x34, 0x15, 0xFD, 0x76, 0xED};
BYTE dst[6];
memcpy(&dst, src+1, 4);
dump(dst);
return 0;
}
void dump(BYTE* bArr){
int x;
for (x = 0; x < sizeof(bArr)/sizeof(BYTE); x++){
if (x > 0) printf(":");
printf("%02x",bArr[x]);
}
}
Now I want another new array which consists of:
Code:
0x34, 0x15, 0xFD, 0x76, 0xED}
So I change
Code:
memcpy(&dst, src+1, 4);
into
Code:
memcpy(&dst, src+1, 5);
Surprisingly, the output is still the same:
Hmm what goes wrong here?