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:
r |
read text mode |
w |
write text mode (truncates file to zero length or
creates new file) |
a |
append text mode for writing (opens or creates file
and sets file pointer to the end-of-file) |
rb |
read binary mode |
wb |
write binary mode (truncates file to zero length or
creates new file) |
ab |
append 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. |