Here is my code for recover.c. It compiles and runs fine, but can only retrieve three out of the sixteen images. I'm not quite sure why it does this.
// Sorry about the formatting of the top part!
int main(int argc, char* argv[]) { // open file FILE* inptr = fopen("card.raw", "r"); if (inptr == NULL) { printf("Could not open %s.\n", "card.raw"); return 2; }
// variables
int count = 0;
int block = 512;
unsigned char buffer[block];
FILE* outptr = 0;
char name[8];
// reads blocks
while (fread(&buffer, sizeof(char), block, inptr) != 0)
{
fread(&buffer, sizeof(char), block, inptr);
// searches for jpegs
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] == 0x30 || buffer[3] == 0xe1))
{
if (count == 0)
{
sprintf(name, "%03d.jpg", count);
outptr = fopen(name, "a");
count++;
}
else
{
fclose(outptr);
char title[8];
count++;
sprintf(title, "%03d.jpg", count);
outptr = fopen(title, "a");
}
}
if (count > 0)
{
fwrite(&buffer, sizeof(buffer), 1, outptr);
}
}
fclose(inptr);
return 0;
}
Thank you!