0

my recover doesn't wanna pass. I've checked similar problem solutions and tried them all to no avail. I've right shifting the bits of the fourth byte by 4 instead of division by 16, and other proposed solutions, stil can't pass. I need help.

    FILE* file = fopen("card.raw", "r");
if (file == NULL)
{
    printf("file couldn't be recovered");
    return 2;
}

char title[8];
int jpegfound = 0;
int n = 512;
BYTE first[n];
FILE* output;
while (!feof(file))
{
    fread(first, sizeof(first), 1, file);

    if (first[0] == 0xff && first[1] == 0xd8 && first[2] == 0xff && ((first[3]/16) == 0xe) )
    {
        sprintf(title, "%03d.jpg", jpegfound);
        output = fopen(title, "w");
        fwrite(first, sizeof(BYTE), 512, output);
        jpegfound++;
    }
    else if (jpegfound > 0)
    {
       fwrite(first, sizeof(BYTE), 512, output);   
    }
}
fclose(file);


return 0;
1
while (!feof(file))

doesn't work the way people think it does, because feof() won't return true until after you've attempted to read past the end of the file. As a result, you are reading an additional block, something that does not like to check 50, the right way is to use the value returned by fread, while read an entire block ....

while(fread(first, sizeof(first), 1, file) == 1;

check your fwrite function, and check that are writing correctly, have not checked your program but two fwrite functions may cause problems

You must log in to answer this question.

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