0
:) recover.c exists.
:) recover.c compiles.
:( handles lack of forensic image
    expected exit code 1, not 0
:) recovers 000.jpg correctly
:) recovers middle images correctly
:) recovers 049.jpg correctly

...

 #include <cs50.h>
 #include <stdio.h>
 #include <stdlib.h>

 #define BUFFER_SIZE 512

  int main(void)
{
// if this doesnt work whole program will be useless
FILE* input = fopen("card.raw", "r");
if (input == NULL)
{
    printf("Could not open card.raw.\n");
    return 1;
}
 // set variables and arrays
unsigned char buffer[BUFFER_SIZE];
int filecount = 0;
FILE* picture = NULL;

int jpg_found = 0; //false not true this time
   while (fread(buffer, BUFFER_SIZE, 1, input) == 1)
{
    // looking for first stage of a jpeg file
    if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xe0) == 0xe0)
    {
         if (jpg_found == 1)
        {
            fclose(picture);
        }
        else
        {
           jpg_found = 1;
        }
       char filename[8];
        sprintf(filename, "%03d.jpg", filecount);
        picture = fopen(filename, "a");
        filecount++;
    }
   if (jpg_found == 1)
    {
        fwrite(&buffer, BUFFER_SIZE, 1, picture);
    }
}
//close the files
fclose(input);
fclose(picture);
 return 0; // everything went good
 }
2

The program is supposed to take the filename of the input file as a parameter. BUT, you've hardcoded it into the program. So, when check50 tests to see if the program terminates when there's no input parameter, it fails.

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 .