Help to recover images on this program. Thank you.
/***************************************
* recover.c
* problem pset4
* computer science 50
* Reccvers JPEGs from a foreinsic image
* **************************************/
#include <stdio.h>
#include <stdint.h>
// unsigned integers type
#define BLOCKSIZE 512
typedef uint8_t BYTE;
int main(int argc, char* argv[])
{
// open memory card
FILE *file = fopen("card.raw", "r");
if (file == NULL)
{
printf("Cannot open file\n");
return 1;
}
// open output file
FILE *outfile = NULL;
// create new image file
int jpgCount = 0;
// forever loop that that will end when the file has been reached
while(1)
{
// array of type BYTE
BYTE image[BLOCKSIZE] = {};
// iterate over byte in each block untill the end of file
for(int i = 0; i < BLOCKSIZE; i++)
{
// close the file when the file is ended
if(feof(file))
{
fclose(file);
if(outfile != NULL)
{
fclose(outfile);
}
return 0;
}
// read one byte at a time
fread(&image[i], sizeof(BYTE), 1, file);
}
// first four bytes match those of jpg
if(image[0] == 0xff &&
image[1] == 0xd8 &&
image[2] == 0xff &&
image[3] == 0xe0 &&
image[3] == 0xe1)
{
// close outfile if it is exit
fclose(outfile);
// an array of filename
char filename[4];
// name file using ###.jpg format
sprintf(filename, "%3d.jpg", jpgCount);
jpgCount++;
// open outfile
outfile = fopen(filename, "w");
if(outfile == NULL)
{
printf("Could not write images\n");
return 1;
}
// photo written to the outfile
fwrite(&image, sizeof(BYTE) * BLOCKSIZE, 1, outfile);
}
}
// close file
fclose(file);
}
img[3] == 0xe0 && img[3] == 0xe1
which will always result in afalse
causeimg[3]
cannot have both 2 values at once. watch the walkthrough once carefully and you will get your answer for this.