0

I am currently working on recover(pset4).I have recovered all 50 images but partially.Don't know what is wrong with the code...Any help is appreciated.Here is the link to the code https://gist.github.com/belogical/cc5c888d850aaac08a54c21536e935c0

1

Ask de Morgan (Disclaimer: I've studied physics, boolean logic was part of the maths curriculum)

The opposite of

data[0]==0xff&&data[1]==0xd8&&data[2]==0xff&&(data[3]==0xe0||data[3]==0xe1)

is

data[0]!=0xff||data[1]!=0xd8||data[2]!=0xff||data[3]!=0xe0&&data[3]!=0xe1

I have some bad feeling about ch=fgetc(inptr); (doesn't this get you out-of-sync?), and also the fseek looks suspicious (as if it wanted to lead you into an infinite loop without that fgetc). Maybe something like if (no == 512) fseek...

Name buffer for the input file name is interesting.

I did it slightly differently, having only one fread, in the while condition. Then, within the loop, on finding a JPEG header, I'd start a new output file, and independently (no else), if there is an open output file, I'd write that block to disk (so also only one fwrite). Personal preference maybe.

| improve this answer | |
  • I want to check the first 4 bytes of the file but using logical OR in place of AND as u have suggested will make the condition false even if anyone byte resembles the starting bytes of jpeg and will close the file which i certainly dont want and no worries about fgetc i was checking for something and i forgot to remove it....sry i didn't get what have u said about fseek.. – belogical Oct 14 '17 at 8:02
  • Next block still goes to the same image if any single byte shows that it's clearly not another JPEG's header. So using OR is correct there to get the full length. – Blauelf Oct 15 '17 at 16:48

You must log in to answer this question.

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