0

below will be my code. on check50 I get:

:( recovers 000.jpg correctly recovered image does not match :( recovers middle images correctly recovered image does not match :( recovers 049.jpg correctly recovered image does not match

The files are created when the program runs and when I check the properties of the jpg it has 113.7 KB.

I am lost on this if someone could walk me on to the line I should focus on.

include

include

int main(int argc, char *argv[]) {

//ensure proper comand line count
if(argc > 2 || argc < 2)
{
    printf("Usage ERROR\n");
    return 1;
}
else
{

    // open the file given in the argument line
    FILE *input = fopen(argv[1], "r");

    // check its got data
    if(input == NULL)
    {
        printf("ERROR %s\n", argv[1]);
        return 1;
    }

    // declear count
    int counter = 0;

    //output pointer
    FILE *picture = NULL;


    // creater buffer memory, allocates 512 bits per block
    unsigned char buffer[512];

    //jpeg found bool logic
    int newjpg = 0;

    while(fread(buffer, 512, 1, input) == 1)
    {
        if(buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
        {
            if(newjpg == 1)
            {
                fclose(picture);
                counter++;
            }
            else
            {
                newjpg = 1;
            }

            char filename[8];
            sprintf(filename, "%03i.jpg", counter);
            picture = fopen(filename, "w");


        }
        else if(newjpg == 1)
        {
            fwrite(&buffer, 512, 1, picture);
        }
    }

    fclose(input);
    fclose(picture);

}

}

0

I'm new to this and also have the same problem...

-Apparently after you read a chunk/block of memory you want to write it in the image file, whether it's a new image or continuing the old one. Does that make sense to you?

-Also, it seems you are using newjpg as kind of a switch, but you never change the value, I mean inside the while loop.

Hope that can help somewhat.

| improve this answer | |
  • after much trial there was nothing wrong with my switch. I just needed to add a second fwrite. – brenrad May 18 at 20:55
  • Sorry my bad... you were right. – Nytswa May 19 at 18:55

You must log in to answer this question.

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