I know i've been asking a lot about this pset, but I assure I have done my research. My program for recover creates all of the files, but when I try to open them it says the file format is unsupported. I have printed some of the data on the files, the header is just like it's supposed to be. For the rest of the file, it shouldn't have any errors, because it was just copyed. Here's my code:
FILE* in = fopen("card.raw", "r");
FILE* op;
char* temp = malloc(8);
int count = -1;
fread(buffer, 512, 1, in);
//keep reading untill there's no data
while(fread(buffer, 512, 1, in) !=0){
if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff){
if(buffer[3] == 0xe0 || buffer[3] == 0xe1){
//if the start of a jpeg is detected, allocate memory for it's name
free(temp);
temp = malloc(8);
count +=1;
}
}
if(count >=0){
//writing the file's name and opening it
sprintf(temp, "%03d.jpg", count);
op = fopen(temp, "a");
//copying the data in the buffer
fwrite(buffer, 512, 1, op);
}
}
//assuring temp is free
free(temp);
Can anyone spot the mistake?
Thank you very much.