I have been struggling with the recover.c of pset4. I am not able to figure out the mistakes. It's taking a lot of time and even though gives non recovered JPEG images. Can anybody please verify my code.
/**
* recover.c
*
* Computer Science 50
* Problem Set 4
*
* Recovers JPEGs from a forensic image.
*/
#include <stdio.h>
#include <stdlib.h>
FILE* tempjpgg;
FILE* sdcard = fopen("card.raw", "r");
int main()
{
if ( sdcard == NULL)
{
printf("corrupted sd card");
return 1;
}
char* jpegname = (char*)malloc(8);
char* tempstorage = (char*)malloc(512);
float check = 0.0;
int i = 0;
do
{
fread(tempstorage, 512, 1, sdcard);
sscanf(tempstorage, "%f", &check);
if ( check >= 4292411360 && check <= 4292411376)
{
sprintf(jpegname, "%03d.jpg", i);
tempjpgg = fopen(jpegname, "w");
fprintf(tempjpgg, "%f", check);
fwrite( tempstorage, 480, 1, tempjpgg);
free(tempstorage);
tempstorage = NULL;
i++;
}
else if ( i != 0)
{
fprintf(tempjpgg, "%f",check);
fwrite( tempstorage, 480, 1, tempjpgg);
free(tempstorage);
tempstorage = NULL;
}
}while( check != (float)EOF);
return 0;
}
check is basically float equivalent of 0xff 0xd8 0xff 0xe(0-f)