[ad_1]
Say I want to create a new struct that contains image data
struct Image {
int *pxl_arr;
int pxl_arr_len;
int img_wdt, img_hgt;
};
And I also had a separate function that opened an image file and copied the contents of the file into an array of integers made on the heap using malloc(), so that some other function could parse that data and use it with the struct Image
int *freadarr (char *fpath) {
FILE *fptr;
long len;
int *buf;
/* code to open file here */
buf = (int *) malloc(len);
/* code to read from file here */
return buf;
}
Then inside of the main()
function, I were to do this:
int main() {
struct Image img;
img.pxl_arr = freadarr(/* whatever the file path is */);
free(img);
return 0;
}
What would free()
do with the struct Image
?
EDIT: img.pxl_arr
, not img->pxl_arr
[ad_2]