1

This is my sandbox link: https://sandbox.cs50.net/checks/0d0024b391314b4597be136798827f98

while(feof(fp)==0)
{
    // recover images
}

Edit: I'm opening only one file at time and I'm closing the last file.

  • Did you close the last file at the end of the program? If not, please post the relevant code. – Cliff B Jul 1 '15 at 22:34
  • also how many files are you opening at the same time? – Kareem Jul 1 '15 at 23:00
  • I have added my code, please have a look. – Sushant Bansal Jul 2 '15 at 7:25
0

You know how to do 2 things:

When you hit the end of a file, and where a jpg begins. Now, a jpg here is divided in chunks of 512 BYTE. It doesn't mean that the size of those jpgs are multiples of 512. So you may have the end of your last jpg say.. being 3 BYTE in a chunk of 512 BYTE and you may not take those 3 BYTE.

You're really close :) Keep on keep it on!

| improve this answer | |
  • Yes, I tried that, but that it didn't really help. I have put that part in comments section of my code, part which I experimented with but didn't really help. Please have a look at my code. – Sushant Bansal Jul 2 '15 at 7:26
  • There is a way to think this the other way around: Checking first in your while loop if you're not at the EOF (the difference between fread and feof:the latter checks for the end of a file, as for the other, check stdio.h on the net).if(eof){fclose(jpg);} .That way, you can turn the issue upside down(It doesn't mean that after fread and fwrite at each turn of the loop you don't need to check again if you're not at the end of file!) – shirotsuki Jul 4 '15 at 23:04

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