My recover program currently successfully returns a single image "001.jpg" which looks good when I open the file. It also returns a second image "002.jpg" which prompts an error for an Unsupported or Invalid Format.
do
{
int current_pic = 0;
char filename[8];
sprintf(filename, "%03i.jpg", file_count);
FILE* img = fopen(filename, "w");
//printf("%i", file_count);
fread(buffer, 512, 1, read_file);
//If first three file BYTES indicate png, create file, write first block to file..
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
current_pic = 1;
//printf("Current Pic: %i \n", current_pic);
file_count ++;
//printf("Filename: %i - - %s \n", file_count, filename);
//Write the buffer into the file.
fwrite(buffer, 512, 1, img);
while (fread(buffer, 512, 1, read_file)==1)
{
fwrite(buffer, 512, 1, img);
buffer[0] = '\0';
}
fclose(img);
}
.
.
.
.
} while (file_count <51);
The above runs well for a single JPG, but then does not move to the next one successfully (though it seems to get to the point of creating the second file).
I was thinking that it gets stuck in the while loop, so I tried pulling out the while loop, which then allowed me to create all 50 files, but without content in them.
Should I be thinking about not using a While at all, and only IF conditionals?
Thanks much for the help.