Further to the question I posed yesterday, in which I couldn't compile as my declaration of buffer was incorrect.
This has now been resolved as you can see in my code below, and the code will in fact compile and run! As far as I can tell, the logic in the program is correct and it should in fact work, but doesn't seem to be. This code is outputting 26 files, all numbered 0-25 (in the syntax required by the pset), but they are all broken jpegs. What have I overlooked?
I also have a couple of other questions which may in fact be related to the problem I'm having.
When the program has opened the
card.raw
file and is reading into the buffer, once the program has completed one loop iteration, how does it know to read the next block of bytes and not just the same ones again?With
fread
andfwrite
, should the first parameter be&buffer
or justbuffer
?Secondly, with the
fread
andfwrite
functions, does it matter whether I'm reading/writing one byte 512 times or 512 bytes one time, or does it only matter that I'm consistent and that the do/while loop condition is set to the correct comparison at the end?
I know this is quite a lot to ask in one question, but I'm very grateful for any insight you can give me.
Thanks in advance!
...code...
do
{
fread(&buffer, sizeof(BYTE), BLOCKSIZE, file);
...code...
fwrite(&buffer, sizeof(BYTE), BLOCKSIZE, output);
...code...
}
while (fread(&buffer, sizeof(BYTE), BLOCKSIZE, file) == BLOCKSIZE);
fclose(output);
fclose(file);
return 0;
}