My recover program recovers 15 jpg files, 000.jpg through 015.jpg. All files open without issue.
However, check50 fails
:) recover.c exists
:) recover.c compiles
:( recovers 000.jpg correctly
:( recovers 001.jpg through 014.jpg correctly
:( recovers 015.jpg correctly
https://sandbox.cs50.net/checks/ee9daf39c3604acb955e7b19ff95e057
There are no issues compiling, and valgrind shows no data leaks. There are no extraneous print outs to the directory, all files are closed.
I know others have experienced similar check50 issues, but none of the fixes seem to apply. I can't figure out what is wrong.
typedef uint8_t BYTE;
int main(int argc, char* argv[])
{
FILE* memcardptr = fopen("card.raw", "r");
FILE* outptr = NULL;
int numJpg=0;
BYTE* buffer=malloc(512*sizeof(BYTE));
char* filename=malloc(sizeof("000.jpg"));
while(fgetc(memcardptr) != EOF)//while not end of card
{
fseek(memcardptr,-sizeof(BYTE), SEEK_CUR);
fread(buffer, sizeof(buffer),1, memcardptr);
if ((buffer[0]==0xff)&&(buffer[1]==0xd8)&&(buffer[2]==0xff)&&((buffer[3]==0xe0)||(buffer[3]==0xe1)))
{
if(outptr!=NULL)
{
fclose(outptr);
}
sprintf(filename,"%03d.jpg",numJpg);
numJpg++;
outptr = fopen(filename, "w");
}
if (outptr!=NULL)
{
fwrite(buffer, sizeof(buffer),1, outptr);
}
}
free(filename);
free(buffer);
fclose(outptr);
// close input file
fclose(memcardptr);
}
I would greatly appreciate any help.