I'm trying to cast a 2D array of unsigned shorts to a 2D array of unsigned chars. I've done this with 1D arrays, but I can't seem to get this to work. What I have kind of works in that a few values print out correctly, but most are wrong.
Code:
int i,j, count;
USHORT **test;
test = (USHORT **)malloc(sizeof(USHORT)*4);
count=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
test[i] = (USHORT *)malloc(sizeof(USHORT)*4);
count++;
test[i][j] = count;
count++;
test[i][j] = test[i][j] | count<<8;
}
}
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
printf("%d\n", ((UCHAR **)test)[i][j]);
}
}
Basically, I'm trying to avoid doing the right shift in the print out. Does anyone see what this issue is?