How to check number of characters successfuly written?
size = fwrite(pBlock, 14+40, 1, fp);
I am not sure what means the 3rd argument and how it should be used. Does that mean that
size = fwrite(pBlock, 14+40, 2, fp);
would write 2x54 bytes to file? Is there some possibility how to check if all characters were successfully written? What if disk runs out of space or there is some problem? Will the return value be 0 instead 1?
fwrite returns the number of elements successfully written; you need to check this against the number of elements you intended to write i.e. those you passed in argument to fwrite.
the return value of fwrite() tells you exactly this.
No it doesn't. The second and third arguments to fwrite are the size of an "item" and the number of items respectively. The return value is the number of items written, not the number of bytes. So if you say size = fwrite(pBlock, 14+40, 1, fp);
and the return value is 1, then the 1 item was successfully written. If size is less than the number of items, then errno will tell you what error occurred.
the 3rd parameter is the number of elements you want to write, the second is the size of each individual element. Supposing you have a struct of size 256 bytes, and you have an array of 100 such structs you want to write, then your second argument would be 256, and the 3rd would be 100; if successful the return value would be 100, and the total number of bytes written will be 100 * 256
Usually (quoting @mutexe) you'd use sizeof (your struct), instead of just 256.
If the call fails you would either get zero returned or the number of items successfully written. So if the disk was full after 45 * 100 bytes have been written (and miraculously your program/system is still running), you will get 45 returned, not 4500.
On success, fwrite() returns the number of items read or written. This number equals the number of bytes transferred only when size is 1. If an error occurs, or the end of the file is reached, the return value is a short item count (or zero).