0

// Recovers Jpegs from Memory card

#include <stdio.h> #include <stdlib.h> #include <stdint.h> typedef uint8_t BYTE;

int main(int argc, char *argv[]) { // Return 1 if more then 1 arg after recover if(argc != 2) { printf("Usage: ./recover image\n"); return 1; }

// open card.raw

FILE *input = fopen(argv[1], "r");

if(input == NULL)
{
    printf("Could not open file\n");
    return 1;
}
// Declare i jpeg counter  filename for jpeg char name
int i = 0;
BYTE buffer[512]; 
char filename[8];
FILE *output = NULL;


while(fread(&buffer, 512, 1, input)==1)
{
     // Read 512 block for  jpeg header 
    if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
    {
        if(!(i == 0))
        {
            fclose(output);
        }
        // if header found create new jpeg file
        sprintf(filename, "%03i.jpeg", i);
        output = fopen(filename, "w");
        i++;
    }
    // copy over data to jpeg file
    if(!(i==0))
    {
        fwrite(&buffer, 512, 1, output);
    }   
}
//I'm going insane.... please help me

fclose(input);
fclose(output);
return 0;

}

1 Answer 1

0

I FOUND THE ANSWER! I misspelled file name .jpeg instead of .jpg

You must log in to answer this question.

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