File Read/Write Access Constants
These constants specify the access type ("a", "r", or "w") requested for the file. Both the translation mode ("b" or "t") and the commit-to-disk mode ("c" or "n") can be specified with the type of access.
The access types are described below.
- Opens for writing at the end of the file (appending); creates the file first if it does not exist. All write operations occur at the end of the file. Although the file pointer can be repositioned using fseek or rewind, it is always moved back to the end of the file before any write operation is carried out.
- Same as above, but also allows reading.
- Opens for reading. If the file does not exist or cannot be found, the call to open the file will fail.
- Opens for both reading and writing. If the file does not exist or cannot be found, the call to open the file will fail.
- Opens an empty file for writing. If the given file exists, its contents are destroyed.
- Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
When the "r+", "w+", or "a+" type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation.