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"

int main(int argc, char *argv[])
    if (argc != 2)
        printf("Usage: ./recover image\n");
        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)
            char filename[8];
            sprintf(filename, "%03i.jpg", q);
            img = fopen(filename, "w");

        if (img != NULL)
            fwrite(buffer, 512, 1, img);

    //close files

    return 0;

Please give me a thorough explanation as to why it has an exit code of 1 and not 0. Thank you!


If you read the error carefully, it states that the compiler gave a return code of 1, not your program. In other words, the code didn't compile.

The check50 system will only upload the specific files it expects and nothing else in order to execute. In this case, it is uploading recover.c only. Your code has an `include "recover.h" statement, so it required the .h file to be available to compile it, but that file isn't being uploaded, and it will not.

You need to move any required statements from the .h file to the .c file, remove the include statement, and try again.

While creating a .h file for the code is correct, and often a judgement call as to whether it is necessary, it is breaking the automated process here.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .