2.12.3.7 fopen

Declaration:

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

Opens the filename pointed to by filename. The mode argument may be one of the following constant strings:

rread text mode
wwrite text mode (truncates file to zero length or creates new file)
aappend text mode for writing (opens or creates file and sets file pointer to the end-of-file)
rbread binary mode
wbwrite binary mode (truncates file to zero length or creates new file)
abappend binary mode for writing (opens or creates file and sets file pointer to the end-of-file)
r+read and write text mode
w+read and write text mode (truncates file to zero length or creates new file)
a+read and write text mode (opens or creates file and sets file pointer to the end-of-file)
r+b or rb+read and write binary mode
w+b or wb+read and write binary mode (truncates file to zero length or creates new file)
a+b or ab+read and write binary mode (opens or creates file and sets file pointer to the end-of-file)

If the file does not exist and it is opened with read mode (r), then the open fails.

If the file is opened with append mode (a), then all write operations occur at the end of the file regardless of the current file position.

If the file is opened in the update mode (+), then output cannot be directly followed by input and input cannot be directly followed by output without an intervening fseek, fsetpos, rewind, or fflush.

On success a pointer to the file stream is returned. On failure a null pointer is returned.