I completed my code and it recovers all images fine. However, when I ran check50 for recover, I received this error code with a domino effect on the rest of them: https://legacy.cs50.me/checks/e03e458c63feebcd62022d1d801c41160c317eb1
:) recover.c exists.
:( recover.c compiles.
expected exit code 0, not 1
:| handles lack of forensic image
can't check until a frown turns upside down
:| recovers 000.jpg correctly
can't check until a frown turns upside down
:| recovers middle images correctly
can't check until a frown turns upside down
:| recovers 049.jpg correctly
can't check until a frown turns upside down```
and this is my code:
#include <stdio.h>
#include <stdlib.h>
//copied bmp file contents into a new header file
#include "recover.h"
//IMPORT BMP.H FILE
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("Usage: ./recover image\n");
//fails
return 1;
}
//file names
char *memory = argv[1];
//open file
FILE *recycle = fopen(memory, "r");
if (recycle == NULL)
{
fprintf(stderr, "Could not open %s.\n", memory);
return 2;
}
//size of each block(buffer)
BYTE buffer[512];
int q = 0;
FILE *img = NULL;
while(fread(buffer, 512, 1, recycle) == 1)
{
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
{
//if img is not null(when first made) then that means its opened before.
if (img != NULL)
{
fclose(img);
}
char filename[8];
sprintf(filename, "%03i.jpg", q);
img = fopen(filename, "w");
q++;
}
if (img != NULL)
{
fwrite(buffer, 512, 1, img);
}
}
//close files
fclose(recycle);
//succeeds
return 0;
}
Please give me a thorough explanation as to why it has an exit code of 1 and not 0. Thank you!