I have managed to finish but i have some queries regarding how fwrite exactly works. If you are new to pset4, the intention of my code is to fwrite the content of triple n times after i have fread triple.

for (int k=0; k<n; k++)
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);


fwrite(&triple, sizeof(RGBTRIPLE), n, outptr);

However, only the former method works. Why so? Any help is appreciated!

1 Answer 1

fwrite(&triple, sizeof(RGBTRIPLE), n, outptr);

This means to write n consecutive blocks of data of size sizeof(RGBTRIPLE)starting at &triple, not to write one block n times.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Hi can you give an example that can express that meaning of consecutive blocks?
    – Yan Bo Pei
    Jun 20, 2018 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .