I have a question regarding a else if statement for the PSET4 Recover
while (fread(buffer, 512, 1, card_raw))
{
if (buffer[0] == 0xff && buffer[1] == 0xd8 && buffer[2] == 0xff && ((buffer[3]) & 0xf0) == 0xe0)
{
if (image_number > 0)
{
fclose(images);
sprintf (filename, "%03i.jpg", image_number);
image_number++;
images = fopen (filename, "w");
fwrite (buffer, 512, 1, images);
}
else if (image_number == 0)
{
sprintf (filename, "%03i.jpg", image_number);
image_number++;
images = fopen (filename, "w");
fwrite (buffer, 512, 1, images);
}
}
else if (image_number > 0) /// <== How does this else if statement connect? Am I right in
/// thinking this just writes to the images after the checks?
{
fwrite(buffer, 512, 1, images);
}
I'm just a bit confused why the code falls apart with blank images if the else if statement is not inserted.
I am wondering if there is a better way to subtract the necessary if statements.