I'm trying to read a matrix of pixels from stdin and just print it. I'm using a structure for the pixels, defined like this:
typedef struct pixel {
int R, G, B;
} RGB;
Allocate space for it
matrixPixels = (RGB**)calloc(height,sizeof(int*));
for(row = 0; row < height; row++)
matrixPixels[row] = (RGB*)calloc(width,sizeof(int));
In main I'm reading the width and height of the matrix and assign values to each pixel like this:
for(row = 0; row < height; row++)
for(column = 0; column < width; column++) {
scanf("%d %d %d ", &matrixPixels[row][column].R, &matrixPixels[row][column].G, &matrixPixels[row][column].B);
Now, my problem would be that when I'm trying to print the matrix using
for(row = 0; row < height; row++)
for(column = 0; column < width; column++)
printf("%d %d %d", matrixPixels[row][column].R, matrixPixels[row][column].G, matrixPixels[row][column].B);
Some values are not what they're supposed to be... As an example, if the width and height are 3 and 2 and I'm reading 87 88 255 40 60 50 70 80 90 55 56 57 66 67 68 77 78 79, when I'm printing it, instead of the value 90 I have 55 for some unknown reason and I can't figure out why...