C I/O

File I/O

For C File I/O you need to use a FILE pointer, which will let the program keep track of the file being accessed. To open a file you need to use the fopen function, which returns a FILE pointer.

FILE *fopen(const char *filename, const char *mode);

The modes are:

r open for reading
w open for writing (file need not exist)
a open for appending (file need not exist)
r+ open for reading and writing, start at beginning
w+ open for reading and writing (overwrite file)
a+ open for reading and writing (append if file exists)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.