I don't know why my code isn't working. It recovers images but only a small fuzzy part of them. Can anyone help?
/** * recover.c * * Computer Science 50 * Problem Set 4 * * Recovers JPEGs from a forensic image. */
include
include
include
typedef uint8_t BYTE; int main(int argc, char* argv[]) { // open memory card file char picture[8]; BYTE block[512]; int counter = 0;
FILE* inptr = fopen("card.raw", "r");
if(inptr == NULL)
{
printf("could not open file/n");
return 1;
}
FILE* outptr;
while(fread(&block, 512, 1, inptr) > 0)
{
if ((block[0] == 0xff) && (block[1] == 0xd8) && (block[2]== 0xff) && (block[3] >= 0xe0) && (block[3] <= 0xef))
{
if( counter > 0)
{
fclose(outptr);
sprintf(picture, "%d.jpg", counter);
counter++;
outptr = fopen(picture, "w");
}
if( counter == 0)
{
sprintf(picture, "%d.jpg", counter);
counter++;
outptr = fopen(picture, "w");
if (outptr == NULL)
{
printf("could not create /n");
return 2;
}
}
fwrite(&block, 512, 1, outptr);
}
}
fclose(inptr);
}