On success, fread() and fwrite() return the number of items read or written.
> 1. fwrite( (void*)Buffer, sizeof(Foo), 128, fp );
The result is a number between 0 and 128, depending on how many records were written.
A record is written completely, or not at all.
> 2. fwrite( (void*)Buffer, sizeof(Foo) * 128, 1, fp);
This runs the risk of having a partially complete record at the end of the file.
but, for 2), you would get 0 result instead of 1, so you can still trap an error, though less precisely if that happened.
if foo or the number of foos is very large, you can also tamper with its buffer to tweak at it but this may not be optimal for all target machines so that is aggravating. If it is not too large, it won't matter, most likely.
fwrite() returns the number of items actually written. If you write 128 items but only say 60 were written correctly - what state is the file actually in given that this is actually an array being written? What about the 60 already written? If you only write as one object then you either have a successful write or you don't - either it's all been written OK or it hasn't.
Internally, the function interprets the block pointed by ptr as if it was an array of (size*count) elements of type unsigned char, and writes them sequentially to stream as if fputc was called for each byte.
(emphasis added).
So the return value is yes/no, but that doesn't mean the write completely sucessful vs. nothing written. I always call fwrite with size=1 and count=(number of bytes to write). That way I know if there was a partial write and do something about it if necessary.