ANSI c requires that the file be opened with a function fopen and closed to fclose.
1. The calling method is usually:
Copy Code code as follows:
FILE *FP;
Fp=fopen (filename, open mode);
2. Parameter Description:
FileName: such as "Myfile.dat", "F:\data\myfile.dat" and so on;
Open mode:
"R" (Read Only) opens a text file for input
"W" (write-only) opens a text file for the output
"A" (append) adds data to the end of the file file
"RB" (Read only) opens a binary file for input
WB (write-only) opens a binary file for the output
"R+" (Read and write) opens a text file for reading and writing
"w+" (Read and write) to create a new text file for reading and writing
"A +" (read/write) opens a text file for reading and writing
"Rb+" (Read and write) opens a binary file for reading and writing
"Wb+" (Read and write) to create a new binary file for reading and writing
"Ab+" (Read and write) opens a binary file for reading and writing
3. Note:
(1) The file opened with "R" can not input data to it, and the file already exists, otherwise error;
(2) The file opened with the "W" method, you can only enter data into the file, and if the file you open does not exist, create a new file named after the specified name, or delete the file when you open it, and then create a new file;
(3) If the function fopen open the file error, fopen returns a null pointer value;
(4) When the program starts running, the system automatically opens 3 standard files: standard input (stdin), standard output (STDOUT), standard error Output (stderr). If you want to use an input-output terminal, you do not need to open it, you can use it directly, such as FPUTC (stdout, ' a '), and output character a to the screen.