Я работаю с 2-мерным массивом структур, который является частью другой структуры. Это не то, что я сделал много, поэтому у меня проблемы. Эта функция заканчивается неудачей после перехода к "тесту" для цикла ближе к концу. Он печатает одну строку правильно, прежде чем она будет устранена.
Части моего кода, которые считывают данные в манекен-2-мерный массив структур, отлично работают, поэтому мой присваивающий массив должен быть частью другой структуры (imageStruct).
Любая помощь будет принята с благодарностью!
/*the structure of each pixel*/
typedef struct
{
 int R,G,B;
}pixelStruct;
/*data for each image*/
typedef struct
{ 
 int height;
 int width;
 pixelStruct *arr; /*pointer to 2-d array of  pixels*/
} imageStruct;
imageStruct ReadImage(char * filename)
{
 FILE *image=fopen(filename,"r");
 imageStruct thisImage;
        /*get header data from image*/
        /*make a 2-d array of of pixels*/
 pixelStruct imageArr[thisImage.height][thisImage.width];
        /*Read in the image. */
        /*I know this works because I after storing the image data in the
          imageArr array, I printed each element from the array to the
          screen.*/
 /*so now I want to take the array called imageArr and put it in the
   imageStruct called thisImage*/
  thisImage.arr = malloc(sizeof(imageArr));
  //allocate enough space in struct for the image array. 
 *thisImage.arr = *imageArr; /*put imageArr into the thisImage imagestruct*/
//test to see if assignment worked: (this is where it fails)
 for (i = 0; i < thisImage.height; i++)
 {
  for (j = 0; j < thisImage.width; j++)
  {
   printf("\n%d: R: %d G: %d B: %d\n", i ,thisImage.arr[i][j].R,
          thisImage.arr[i][j].G, thisImage.arr[i][j].B);
  }
 } 
 return thisImage;
}
(В случае, если вам интересно, почему я использую фиктивный массив в первую очередь, ну, потому что, когда я начал писать этот код, я не мог понять, как делать то, что я пытаюсь сделать сейчас.)
EDIT: Один человек предположил, что я не инициализировал свой 2-мерный массив правильно в typedef для imageStruct. Может ли кто-нибудь помочь мне исправить это, если это действительно проблема?
