I am completely stuck right now when it comes to implement:

Write 512 bytes until the new jpeg is found.

Could anyone give me idea how to implement this step?

Here is my code:

 // Declare buffer array
BYTE buffer[512];

 // Initializing JPEG image
int count = 0;

// Repeat until end of card
    // Read 512 bytes into buffer
    fread(buffer, 512, 1, inptr);
    // Find the beginning of JPEG image
    if(buffer[0] == 0xff &&
       buffer[1] == 0xd8 &&
       buffer[2] == 0xff &&
       (buffer[3] & 0xf0) == 0xe0)
        char filename[8];
        sprintf(filename, "%03i.jpg", count);
        FILE *img = fopen(filename, "w");

        // write 512 bytes until the new jpeg is found
        fwrite(buffer, 512, 1, img);



How about an explanation instead. Image files are not just 512 bytes long. They can be any size. The assignment is saying this. You need to read in blocks of data that are 512 bytes long and check the first 4 bytes of each block for a signature. Once you find the first signature, all the data that follows is part of an image file.

Once you find a block with a signature, that is the first block of a file. It has to be written out to an output file. Now, here's what you don't get. Every block that follows has to be written out to the same file until you find another block with a signature.

When you find another signature block, you need to close the existing output file, open a new output file, and continue the process.

Finally, when you get to the end of the input file, just close the open output file and end the program.

Does that explain it?

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 .