Fopen
Purpose: To open a file. Fclose () is used to close the file ()
Header file: stdio. h
R: open a read-only file, which must exist. R + open a readable file, which 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 + opens 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.
If A, A + is used, the end of the actual file is written. The fseek () function is used in the test to move the file location pointer to the beginning of the file, and then fwrite () writes data. It is found that the write is still at the end of the file.
Solution: You can use R +, but use R +. The file must exist.