fwrite writes size*nmemb bytes from a memory buffer to the current position of a stream. Its prototype accepts a pointer, object size, object count, and FILE stream; the return value reports how many bytes were written, usually size*nmemb. section 14.6
size_t fread(void* restrict ptr, size_t size, size_t nmemb,
FILE* restrict stream);
size_t fwrite(void const*restrict ptr, size_t size, size_t nmemb,
FILE* restrict stream);
int fseek(FILE* stream, long int offset, int whence);
long int ftell(FILE* stream);
Use the prototype listing to compare fwrite with fread, fseek, and ftell: these interfaces operate on the same stream position. section 14.6
Writing an in-memory byte array
unsigned char data[] = { /* binary data */ }; size_t written = fwrite(data, 1, sizeof data, stdout); Here, fwrite requests one-byte objects and writes sizeof data bytes to stdout. A result smaller than the requested amount indicates that the write did not complete successfully. section 14.6 section 14.6
For portable binary I/O, open the stream in binary mode. Binary mode suppresses translation between the file’s external representation and the program’s internal bytes; without it, a program can work on one platform and fail on another. section 14.6 section 14.7
The stream’s file position advances after a successful write. Combine fwrite with fread, ftell, and fseek to move through a binary file and preserve an object’s internal representation for later reading. section 14.6

