So my code creates the correct number of files in the correct format but they are all empty with the exception of number two that had the first couple of lines but the rest is also empty.

Why is it no writing the image?

// Iterate until end of memory card
while (fread(buffer, 512, 1, infile) == 1)

    // Check if it is a JPEG
    if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && (buffer[3] & 0xf0) == 0xe0)
        // Check if its the first JPEG
       // if (jpegfound == 0)
      //  {
            // Name the JPEG file name
            sprintf(filename, "%03i.jpeg", jpegfound);

            // Create outfile
            outfile = fopen(filename, "w");

            //Write first jpeg
            fwrite(buffer, 512, 1, outfile);

            // Increase counter

            // Close last file

You're writing 512 bytes and then you are closing the output file. You have to keep the file open and keep writing each block as you read it until you find the next signature, and then you can close the first jpg file and open the next one.

You must log in to answer this question.

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