0

/** * recover.c * * Computer Science 50 * Problem Set 4 * * Recovers JPEGs from a forensic image. */ #include #include #include #include

int main(void) {

FILE* card = fopen("card.raw", "r");
if (card == NULL)
{
    fclose(card);
    printf("Could not open %s\n", "card.raw");
    return 1;
}
FILE* images = NULL;
uint8_t buffer[512];
char title[8];
int counter = 0;


while(fread(buffer, 512, 1, card) == 1)
{
    if(buffer[0] == 0xff && buffer[1] == 0xd8 &&
    buffer[2] == 0xff)
    {
        if(buffer[3] <= 0xef || buffer[3] >= 0xe0)
        {
            counter++;
            sprintf(title,"%03d.jpg",counter);

            if(images != NULL)
                {
                    fclose(images);
                }

            images = fopen(title,"w");
            if(images == NULL)
                {
                printf("error opening imagefile\n");
                return 1;
                }
            fwrite(&buffer, 512, 1, images);

        }
    }
}
fclose(images);

fclose(card);
return 0;

}

4
  • Why are they blank? What did you do to try and find the cause? meta.cs50.stackexchange.com/questions/63/…
    – Cliff B
    Commented Dec 7, 2016 at 3:55
  • I forgot what I did, sorry I managed to solve this, submit and got a 1.0. Just closing this thread :)
    – cfdphd
    Commented Feb 17, 2017 at 18:41
  • In that case, can you please add an answer and, importantly, accept the answer? Otherwise this question will stay in the unanswered question pool forever. thanks.
    – Cliff B
    Commented Feb 17, 2017 at 22:16
  • Problem was resolved by combining the buffer check into one statement.
    – cfdphd
    Commented Feb 20, 2017 at 2:50

1 Answer 1

0

Resolved by combining buffer check statements into one if statement.

You must log in to answer this question.

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