recover.c
seems to be working just fine. But then I realized I didn't employ a condition which tests the end of file. Why does it still
work then? Should I modify my while
condition?
In addition to that I don't really get why recover.c
fails the check50
test if I don't
initialize the pointer img
to NULL
.
Here's the code. (Pseudocode starts with the while loop).
int main(int argc, char* argv[])
{
uint8_t buffer[512];
char title[8];
FILE *img = NULL; //FILE *img; -> this won't let me pass the check50 test
int count = 0;
FILE *card = fopen("card.raw", "r");
if (card == NULL)
{
printf("Could not open %s.\n", "card.raw");
return 1;
}
while(fread block of size buffer)
{
if (jpeg headers are found)
{
check if img is open otherwise close it
sprintf the img
open a new img
fwrite onto img
}
else if img is open
{
fwrite onto img
}
}
fclose(card);
return 0;
}