C语言文件操作函数大全(国外英文资料)
C语言文件操作函数大全
First, read and write standard documents
1. file open, fopen ()
The file open operation that will give the user specified file in the memory allocation of a FILE structure, and the structure of the pointer returned to the user program, after the user program is available in this FILE pointer to achieve access to the specified file operation. When using the open function, must give the file name, file operations (read, write or read and write), if the file name does not exist, it means to establish (only to write files to read the file, then the error), and the file pointer to the beginning of the file. If there is already a file with the same name, the file is deleted. If it does not have the same name file, the file is created and the file pointer is pointed at the beginning of the file.
Fopen (char, *filename, char, *type);
Where *filename is the file name pointer to open the file, usually expressed in double quotes, and also can be separated by double slashes. The *type parameter indicates how to open the file. The mode of operation available is as follows:
Mode meaning
"R" opens, read-only
"W" opens, the file pointer refers to the end, and only writes
"A" opens, points to the end of the file, and is appended to the existing file
"RB" opens a binary file that is read only
"WB" opens a binary file and writes only
"Ab" opens a binary file and appends it
"R+" opens an existing file in read / write mode
"W+" creates a new text file in read / write mode
"A+" opens a file file to append by reading / writing
"Rb+" opens a binary file in read / write mode
"Wb+" creates a new binary file in read / write mode
"Ab+" opens a binary file for additional purposes by reading / writing
When fopen (0 successfully opens a file, the function returns a FILE pointer and returns a NULL pointer if the file opens. If you want to open the test file, write it:
FILE *fp;
If ((fp=fopen ("test", "W")) ==NULL)
{
Printf ("File cannot be opened\n");
Exit ();
}
Else
Printf ("File open