Hope all is well.

This is probably a stupid question but I am going to ask it anyway.

I have finally finished Recover (PSET4). I initially dynamically allocated an array as follows to store my 512 bytes of data from the memory card:

#define BLOCK 512
BYTE* starter_array = malloc(BLOCK)
if (starter_array==NULL)
    return 2;

Well a (very) long story short I managed to create all the JPEGs but they seemed to be all corrupted as none of them would open. Then I decided to change to a static array using the following:

BYTE starter_array [BLOCK];

and it worked straight away and it passed check50. But why is this the case? Obviously there is a difference between the two but I just figured you could just pass values in and out of both arrays in a similar way.

I can share my full code if you wish also.

If anybody has any suggestions I would love to hear them. Many thanks!

1 Answer 1


So I was working on my code this morning and I think I figured it out

in my

fwrite (starter_array,BLOCK,1,img);

and my

(fread(starter_array, BLOCK, 1, inptr); 

I initially used an & in front of array name so the code looked like this.

fwrite (&starter_array,BLOCK,1,img);


(fread(&starter_array, BLOCK, 1, inptr);

So I reckon with using the &starter_array I was freading and fwriting to an address to a pointer rather than freading and fwriting to an actual pointer to an array. I removed all &'s and the all it passed check50 regardless of using a dynamic array or a static array.

If anybody has an suggestions please let me know. thanks.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .