Mode
The mode parameter specifies the type of access required to the stream. Can be the following:
fopen () list of possible values in mode |
Mode |
Description |
' R ' |
Read-only opens, pointing the file pointer to the file header. |
' R+ ' |
Read-write mode opens, pointing the file pointer to the file header. (that is, overwrite) |
' W ' |
The Write method opens, pointing the file pointer to the file header and truncating the file size to zero. (That is, when the file pointer is pointed to the file header and the file is emptied), if the file does not exist, try to create it. |
' w+ ' |
Read-write mode opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it. |
A |
Write to open, pointing the file pointer to the end of the file. If the file does not exist, try to create it. (equivalent to append) |
' A + ' |
Read-write mode opens, pointing the file pointer to the end of the file. If the file does not exist, try to create it. |
' X ' |
Creates and opens in writing, pointing the file pointer to the file header. If the file already exists, the fopen () call fails and returns false , and generates an e_warning level error message. If the file does not exist, try to create it. This specifies o_excl| for the underlying open (2) system call The O_creat tag is equivalent. |
' x+ ' |
Created and opened in read-write mode, other behaviors are the same as ' X ' . |
' C ' |
open the file for writing only. If The file does not exist, it is created. If it exists, it is a neither truncated (as opposed to ' W ' ), or the call to this function fails (as was the case WI Th ' x ' ). The file pointer is positioned on the beginning of the file. This could be useful if it's desired to get a advisory lock (see Flock ()) before attempting to modify the file, as using the em> ' W ' could truncate the file before the lock was obtained (if truncation are desired, ftruncate () can be used after The lock is requested).   |
' C+ ' |
Open the file for reading and writing; Otherwise it has the |
Same behavior as ' C '.
Mode in the fopen (20161115)