fopen opens a file resource, in order to read, write or append content to it.
fopen
opens a file resource, in order to read, write or append content to it. It originated in the C standard library, but has been ported to other languages (and sometimes renamed simply to open
).
In the C standard library, fopen
resides in stdio.h
, with the signature FILE *fopen(const char *path, const char *mode);
.
For example:
FILE *file_pointer = fopen("filename","r");
Generally, there are 3 modes:
- r, which opens a file for reading
- w, which opens a file for writing (clearing it in the process)
- a, which opens a file for appending to the end
- There are also a selection of "hybrid" modes (r+, w+, a+) whose names vary by language
To close an open file, see fclose.