0

When it comes to recover.c for pset4, I am completely lost.

fread(&data, size, number, input);

To quote the video, "where &data is the pointer to a struct which will contain the bytes you’re reading."

What is the struct for recover.c? For resize.c, we had the bmp.h structure.

Or should I use an array instead of a struct?

If I declare an array:

BYTE temp[512];

Do I have to malloc when I create it and just how do I do that?

Sorry, I'm really lost and any help is greatly appreciated.

1

You're on the right track.

You don't need to malloc()... it can be done with an array just like you declared... now you fread() 512 bytes into that array and check the first four bytes with temp[0], temp[1], temp[2] etc and compare those against what should be a JPG signature. And so on.

And if you haven't already, watch Zamyla's walkthrough and it will prove very helpful: https://www.youtube.com/watch?v=Y4vV61lbL3g

4
  • Thank you Yuri! I did watch the video, where the slide reads "&data: the pointer to a struct which will contain the bytes you're reading." I took that literally thinking I had to set up a struct. So if I'm using the array above, temp, how would my fread work? fread( &temp, 4, 1, inptr) ???? – Holly Huber Oct 10 '16 at 19:10
  • You don't need to use the & operator, because an array name works like a pointer, so you can just fread(temp, 4, 1, inptr) – Yuri Laguardia Oct 10 '16 at 19:21
  • 1
    Yeah Yuri! You are such a big help. I appreciate you taking the time to walk me through this! – Holly Huber Oct 10 '16 at 19:28
  • No problem! Glad to help. But remember to read 512 bytes at a time, using 512 instead of that 4 in your example, like: fread(temp, 512, 1, inptr) or fread(temp, 1, 512, inptr) – Yuri Laguardia Oct 10 '16 at 20:00

You must log in to answer this question.

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