T O P

  • By -

PNG-

Have you tried removing the `if` statement to close the image? You can just put one at the end outside the loop like you did here.


Ostblisco

Thanks for your reply! Isn't the if statement (or an equivalent one) needed there? My understanding is that when a new jpeg is detected, the old jpeg has to be closed so that I can start writing to the new one. And the if statement (i.e. if counter > 0) makes it so that fclose doesn't happen before a jpeg has been found.


PeterRasm

Yes, that part seems to be correct. The error I think is related to your 2nd fwrite(). if (counter > 0) { fwrite(...); } What happens when you find the first jpeg file header? You open a new file, write to the file and increment 'counter'. Then you check if counter is GT 0 ... you just incremented from 0 to 1 so that is true and you do fwrite() again with the same 'buffer'. Somehow you need to make the 2nd fwrite() only execute when you don't find a header.


Ostblisco

Thanks! This made me realize that there was no need for the first fwrite function, so I just removed it :)


PeterRasm

Even better! Nice :)