R: open a read-only file, which must exist.
R + has read/write attributes. It is written from the file header and retains the content not covered in the original file.This file must exist.
W. Open and write only the file. If the file exists, the file length is 0, indicating that the file content will disappear. If the file does not exist, the file is created.
W + open the readable and writable file. If the file exists, the file length is cleared to zero, that is, the file content disappears. If the file does not exist, the file is created.
A. Open and write-only files as an attachment. If the file does not exist, the file will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained.
A+ Open readable and writable files by appending them. If the file does not exist, the file will be created. If the file exists, the written data will be added to the end of the file, that is, the original content of the file will be retained.
A and A + are described as follows:
"A" mode does not clear the EOF flag before adding the data. After adding the data, use the Type command of the MS-DOS to only display the data to the original EOF flag without displaying the later added.
The "A +" Mode clears the EOF flag and displays all the data with the Type command of the MS-DOS after adding the data.In the "A +" mode, you need to enter the stream that ends with the CTRL + z EOF sign.
However, I tried to write the same characters using a and a + in Linux, and there is no difference in EOF:
For example, if the content of the original file is ABC, if the mode is used to add 123, then read the file, stop the output when the EOF mode is encountered, and finally show ABC123, if according to the above statement, only ABC is displayed.
If the + mode is used, the last displayed value is abc123.
Therefore, the above statement is not true in Linux and may be used in windows.
Finally, the description in man fopen in Linux:
A open for appending (writing at end of file). The file is created if it does not exist.
Stream is positioned at the end of the file.
A + open for reading and appending (writing at end of file). The file is created if it does not
Exist. The initial file position for reading is at the beginning of the file, but output is
Always appended to the end of the file.
The EOF problem is not mentioned above.