I am iterating over 1 BYTE at a time, reading it from file to allocated memory, then checking if it's the start of a new jpg, or if it's the end of the file, and if not, writing it to the currently open jpg file (img). This code works, however I see that I check if it's a new jpg header, or if it's the end of the file, then write, then check the same thing over again before starting the loop again. Since each loop is checking these 2 conditions twice, I reckon it is going to use unnecessary computing power making the code slower. Thanks for any suggestions!
do
{
fread(p, sizeof(BYTE), 512, file);
if (!(p[0] == 0xff && p[1] == 0xd8 && p[2] == 0xff && (p[3] & 0xf0) == 0xe0) && (!feof(file)))
{
fwrite(p, sizeof(BYTE), 512, img);
}
}
while (!(p[0] == 0xff && p[1] == 0xd8 && p[2] == 0xff && (p[3] & 0xf0) == 0xe0) && (!feof(file)));