0

I have been working on the "recover", however although it compiles but it tend to run into an infinite loop when searching for the start of the jpgs. Here are my coding for searching the start of the images:

//finds beginning of jpg file           
do //if not jpg
{
    fread(&buffer, sizeof(buffer), 1, inptr);//read another unit
    fseek(inptr, +sizeof(buffer), SEEK_CUR);
    printf("loading...\n");
}
while (isjpg(buffer) == 1);

//find jpg funtion
int isjpg ()
{
    unsigned char buff[512];

    if  (buff[0] == 0xff && buff[1]==0xd8 && buff[2]==0xff && (buff[3] == 0xe0 || buff[3] == 0xe1))
    {
        return 0;
    }    
    else return 1;  
}

1 Answer 1

0

I'm afraid, you're not on the right track. For example, you shouldn't fseek or print any output. Also your isjpg is likely to be always returning 1 which causes the infinite loop. This is because buff is actually declared locally inside isjpg and its elements are not initialized by default.

Here are some hints:

  1. use a pencil and a paper and try sketching out a picture the represents part of the raw file (the represents the SD card in this case) and how the data is stored inside it.

  2. try, as a human, extracting the data inside as instructed by the specs. Recall that the file contains blocks of 512 bytes each and each JPG is followed directly by another JPG.

  3. record the steps as you're presumably extracting these JPGs.

  4. try converting that into an algorithm and try applying it programatically.

1
  • thank you, and I will draft out the logic again:) Commented Feb 27, 2015 at 13:27

You must log in to answer this question.

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