I was wondering if anyone could give me some guidance on this problem. I have the below code. When it runs, I see 000.jpg to 049.jpg, however all the pictures are black boxes? I'm not quite sure what's causing this? I would assume it's within fwrite?
while(fread(bytes, 512, 1, file)==1)
{
if (bytes[0] == 0xff && bytes[1] == 0xd8 && bytes[2] == 0xff)
{
if(bytes[3] == 0xe0 || bytes[3]== 0xe1 || bytes[3]==0xe2 || bytes[3]==0xe3 || bytes[3]==0xe4 || bytes[3]==0xe5 || bytes[3]==0xe6 || bytes[3]==0xe7 || bytes[3]==0xe8 || bytes[3]==0xe9 || bytes[3] == 0xea || bytes[3]==0xeb || bytes[3]==0xec || bytes[3]==0xed || bytes[3]==0xee || bytes[3]==0xef)
{
if(jpeg == 0)
{
sprintf(filename, "000.jpg");
img = fopen(filename, "a");
}
else if (jpeg<10 && jpeg >0)
{
fclose(img);
sprintf(newfilename, "00%d.jpg", jpeg);
img = fopen(newfilename, "a");
}
else
{
fclose(img);
sprintf(newfilename, "0%d.jpg", jpeg);
img = fopen(newfilename, "a");
}
fwrite(bytes, 512, 1, img);
jpeg++;
}
}
if (jpeg>=1)
{
fwrite(bytes, 512, 1, img);
}
}
fclose(file);
fclose(img);
free(ptr);
}