Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

malloc and nested struct problems... need help asap please.

$
0
0
Alright so im working on a homework assignment in which i have to make a ppm image sepia. Im pretty sure the other 90 percent of my program is fine but i seem to be messing up on my malloc 's, this is what i have;

Structures (premade by teacher and cant be changed:

/** pixel_t definition **/
typedef struct pixelType {
   unsigned char r;
   unsigned char g;
   unsigned char b;
} pixel_t;

/** image_t defintion **/
typedef struct imageType {
   pixel_t *image;
   int     columns;
   int     rows;
   int     brightness;
} image_t;




my code:

image_t *sepia(image_t *inImage, int depth) {

image_t *sepiaImage;

sepiaImage = malloc(sizeof(image_t));
sepiaImage->image = malloc(sizeof(pixel_t));



inImage is already initialized, what i believe the problem is, is that im not allocating the memory right for sepia->image. infact when i copy inImage into sepiaImage the rows, columns and the such appear to be right however the colors are jumbled and dont resemble what they should. It does compile with no errors or warnings so i cant go on that.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>