Transpose a 1D byte-wise array to a 2D array

sample

#include <stdio.h>
#include <string.h>

int main(void){
    unsigned char a[64*128];
    int i,r,c;
    for(i=0;i<64*128;i++){
        a[i]=i;
    }
    //not fill
    unsigned char (*b)[64][128] = (unsigned char (*)[64][128])a;
    for(r=0;r<64;++r){
        for(c=0;c<128;++c){
            printf("%i,", (*b)[r]);
        }
        printf("\n");
    }
    //FILL
    unsigned char b2[64][128];
    memcpy(b2, a, sizeof(b2));
    printf("\nFill ver\n");
    for(r=0;r<2;++r){
        for(c=0;c<16;++c){
            printf("%i,", b2[r]);
        }
        printf("\n");
    }

    return 0;
}

Browse More Popular Posts

Leave a Comment