i am really confused as to why i am getting 0 in my gradebook for recovery. It recovers all the photos and returns check50 with green smiley faces. I don't know what to fix it there is no problems reported and program recovers the photos successfully. I am posting my code below. Would greatly appreciate any tips as what should i look into. thank you!
int main (int argc, char* argv[])
{
if (argc > 1)
{
printf ("No argument necessary");
return 1;
}
FILE* mem_card = fopen("card.raw","r");
if (mem_card == NULL)
{
return 2;
}
unsigned char buffer [512];
fseek(mem_card, 0, SEEK_END);
int file_length = ftell(mem_card);
int times = file_length / 512;
fseek(mem_card, 0, SEEK_SET);
int counter = 0;
FILE * output = NULL;
char* title [16]= {"000.jpg","001.jpg", "002.jpg","003.jpg", "004.jpg","005.jpg", "006.jpg","007.jpg", "008.jpg","009.jpg", "010.jpg","011.jpg", "012.jpg","013.jpg", "014.jpg","015.jpg"};
int no_jpg = 0;
while(counter < times)
{
for (int i = 0; i < 512; i++)
{
if (feof(mem_card))
{
fclose(mem_card);
return 0;
}
fread (&buffer[i], 1, 1, mem_card);
}
counter++;
if (buffer[0] == 0xff && (buffer[1] == 0xd8) && (buffer[2] == 0xff) && (buffer[3] == 0xe0 || buffer[3] == 0xe1))
{
if (output == NULL)
{
output = fopen(title[no_jpg], "w");
if (output == NULL)
{
return 1;
}
no_jpg++;
fwrite(&buffer, 512, 1, output);
}
else if (output != NULL)
{
fclose(output);
fopen(title[no_jpg], "w");
if (output == NULL)
{
return 1;
}
no_jpg++;
fwrite(&buffer, 512, 1, output);
}
}
else if (output != NULL)
{
fwrite(&buffer, 512, 1, output);
}
}
fclose(output);
fclose(mem_card);
}