Problem z kodowaniem przy użyciu dwuwymiarowej tablicy struktur wewnątrz innej struktury w C

Pracuję z 2-wymiarową tablicą struktur, która jest częścią innej struktury. To nie jest coś, co zrobiłem dużo, więc mam problem. Ta funkcja kończy się niepowodzeniem po przejściu do „testu” dla pętli pod koniec. Wypisuje poprawnie jedną linię przed błędami seg.

Części mojego kodu, które odczytują dane do sztucznej tablicy 2-d struktur, działają dobrze, więc to musi być moja tablica przypisująca, aby być częścią innej struktury (imageStruct).

Każda pomoc byłaby bardzo mile widziana!

/*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;
}

(Jeśli zastanawiasz się, dlaczego w pierwszej kolejności używam sztucznej tablicy, to dlatego, że kiedy zacząłem pisać ten kod, nie mogłem się dowiedzieć, jak zrobić to, co próbuję teraz zrobić).

EDYCJA: Jedna osoba zasugerowała, że ​​nie zainicjowałem poprawnie mojej tablicy 2-d w typedef dla imageStruct. Czy ktoś może mi pomóc to poprawić, jeśli rzeczywiście jest to problem?

questionAnswers(5)

yourAnswerToTheQuestion