UPDATE 1 code:
char* buff; is a problem. Remember, a
char is in the range of 0 - 127. Use a "byte" type, as in bmp.h from recover.
Program always writes a block that is not a sig block, therefore it will be writing the "garbage" data from the beginning of the raw file to the first (
000) jpg. It needs (at least) one more test
First a small problem:
"00%i.jpg". This says "pad with 0 to a maximum width of 0". So there will be no padding at all. The output will be
2.jpg, etc instead of
Now the really big problems:
while(fgetc(src)!=EOF) reads one character at a time. The next thing it does is
fread(&tmp,sizeof(JBLK),1,src);: ie, read the next 4 bytes. The chances that it will find a jpg signature at a 512-byte boundary are low (8 out of 50 perhaps?). And it also increases the liklihood that it will find a sig in the middle of a block! The "unit-of-measure" for this assignment is 512-byte blocks because a jpg starts on a block boundary, and occupies X blocks.
- within the while loop, program only reads and writes 4-byte (
fsetpos are file position functions, they don't access any data in the file.
It might serve you well to watch the walkthrough again. Pay special attention to the psuedocode at 8:00. You need to read the file in 512-byte chunks, and decide what to do with each chunk. There are only 3 choices:
- If no jpg found yet, ignore it.
- If it's a jpg signature, start a new jpg.
- Otherwise, write block to current jpg.