On this page
fwrite
Prev: fread | Up: stdio.h | Next: fseek
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — fwrite
Tags: #public #prog #c #stdlib #stdio #tier/core
Include
#include <stdio.h>
Signature & Overview
size_t fwrite(const void *restrict buf, size_t size, size_t count, FILE *restrict stream);
Writes count objects of size bytes to stream; returns the number of objects written.
Notes & Pitfalls
- Always compare the return count against
nmemb: A short write indicates disk-full or I/O failure.
Example
#include <assert.h>
#include <stdio.h>
int main(void) {
FILE *f = tmpfile();
const char msg[] = "data";
assert(fwrite(msg, 1, 4, f) == 4);
fclose(f);
}
Linked from
Related notes
- tuts/c/stdlib/stdio/fread Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fseek Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/fclose shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/feof shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/ferror shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fflush shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fgets shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fopen shared tags: #c, #prog, #stdio, #stdlib, #tier