So, I have finished recover.c (2016 edition) and it recovers all 50 of the jpg-s, and labels tham from 000 to 049.
I have looked at every jpg, and they seem intact, all of them (I opened each of them individually - took forever with the IDE). Yet when I pass my code to check50 I get:
:) recover.c exists
:) recover.c compiles
:) recovers 000.jpg correctly
:( recovers middle files correctly
:( recovers last file correctly
I have no idea what may be wrong. I'm currently trying valgrind to check for leaks (doubt I have any or it counts for check50).
I'll post here part of my code. If anyone can shed some light on what may be wrong, that would be superb.
while (true)
{
//checks if end of the card is reached
if (fread(&buffer, sizeof(BYTE), 512, inptr) != 512)
{
fclose(inptr);
break;
}
else
{
// finds the start of jpgs
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && buffer[3] <= 0xe0 && buffer[3] >= 0xe0)
{
found = true;
// creates a jpg file for me to write into
sprintf(title, "%03d.jpg", piccount);
// opens file for writing
FILE* image = fopen(title, "w");
// writes the first 512 bytes to the outfile
fwrite(&buffer, sizeof(BYTE), 512, image);
fclose(image);
piccount++;
}
else if (found == true)
{
// appends additional bytes til new jpg is found
FILE* image = fopen(title, "a");
fwrite(&buffer, sizeof(BYTE), 512, image);
fclose(image);
}
}
}