so, PPMImage *data = (PPMImage *)malloc(RANGE);
creates a new local variable, of type PPMImage
(a structure!) and is not accessing the img.data
which I think you want ...
Edit to answer the question in the comment
modify struct ppm
to have a pointer to a char:
typedef struct ppm {
unsigned xsize;
unsigned ysize;
char* data;
} PPMImage;
and then (assuming there is a byte matrix with R,G,B):
img.data = malloc(3 * img.xsize * img.ysize);
// do error checking ...
and then
fread(img.data, 3 * img.xsize, img.ysize, handle)
// do error checking ...