I need to read 4 byte blocks from input (see below).
#include <stdio.h>
#include <stdlib.h>
unsigned char input[4][8] = {{'A', 'B','C','D','A','B','C','D'},
{'A', 'B', 'C', 'D','A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D','A', 'B', 'C', 'D'},
{'A', 'B', 'C', 'D','A', 'B', 'C', 'D'}
};
unsigned char output[4][2];
int main(void) {
int line_num;
unsigned int *ptr=(unsigned int*)&input;
for (line_num=0; line_num < 4*2; line_num++) {
unsigned char *arr1 = ( (unsigned char*)ptr );
printf("==> line_num %d: %c%c%c%c\n", line_num, *arr1, *(arr1+1), *(arr1+2), *(arr1+3));
ptr++;
}
return EXIT_SUCCESS;
}
Right now, I'm just using an integer pointer to read 4 bytes and a char * pointer to iterate through 4 byte blocks; This works for a large endian, but will not work for a small endian. Is there a more general and order independent approach to this in "C"?