Hot answers tagged

13

The point of fread/fwrite is to write N elements, each of size S bytes. The API is not a simple 'write this number of bytes' interface. Thus, for example: struct S { int a, b; float c; }; struct S stuff[92]; fwrite(stuff, sizeof (struct S), 92, stream); (I would not write '92' in real code, but I want the simple formulation in this example) Thus it has two ...


6

AT&T's documentation for fread and fwrite that pre-dates size_t is quoted below. But first, to answer the title question: Both functions are designed for objects, not characters. This is evidenced by the return value being a count of the objects read or written, not the number of characters. Each function may read/write fewer objects than requested. ...


3

For STDIO files with no buffering, referring to "raw" devices, like tapes, it is important how the write system calls are issued, because each write system call results in a tape block of the specified size (and to read a raw block, a read system call of size no less than the block size is required). The fwrite/fread API appears to facilitate ...


Only top voted, non community-wiki answers of a minimum length are eligible