0

I am content on how to read a single 512 byte block in recover, however I'm extremely confused on how to go through the rest of the blocks of the memory card i.e can you do this using fread?

I was trying to see how big the card.raw file was using sizeof but that doesn't work.

I know that:

BYTE *memblock = malloc(512);
int filesize = fread(memblock, 512, 1, file);

will read the first block of data into memblock that I can look at. However I have no idea how to obtain the number of elements I want to look at to the amount that is contained on the file and then step through them. Once I know how to do that I know I should be able to complete the rest of it. But this is stumping me.

0

Actually you can solve it without knowing the size of the memory card

some hints

  1. fread returns the number of bytes that the function read, so u can assume that once fread reached the end of the memory card it will not return the amount you wanted to read, in this case the 512 bytes.

  2. fread will continue to read the next 512 bytes if you used a loop (u can use the fread return value as your condition for the loop) (try to figure it out on your own if you cant just let me know).

GL HF.

3
  • Thanks, the whole fread will continue on to the next 512 bytes wasn't clear. So i think I've made a decent attempt at it but I'm getting a seg fault and I have no idea why.
    – funprog31
    May 8 '20 at 15:34
  • I remember getting a seg faults because of the array of chars that I used to change the name of the outputted jpg files however it could be something else. Try posting your code if you couldn't figure out the seg fault on your own. May 8 '20 at 19:02
  • thanks but i managed it.
    – funprog31
    May 9 '20 at 16:53

You must log in to answer this question.

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