file: A struct that contains the file name, file status, and the current location of the file for the C language contained in stdio.h.
Different compiler stdio header files have a slightly different definition of file, as defined in standard C:
int _flag;//read-write status flag bit int _file; Validation of file validity int _charbuf; Check the buffer condition and do not read int _bufsiz If no buffer is present; File size Char *_tmpfname;//temp file name};typedef struct _IOBUF file;
The general form of the definition file pointer is: file *FP; (file is the structure of the buffer, FP is a pointer to the file buffer)
We use fopen to return a file pointer (pointer to the file struct) for file manipulation.
Open files: File *fopen (char const *name,char const *mode);
File operating modes (mode):
R: Create file, read in
w: Create a file for writing. If the file already exists, delete the current content
A: Append, open or create file to write at end of file
r+: Open file for update (read and write)
w+: Create a file to update. If the file already exists, delete the current content.
A +: Append, open or create a file to update, write at the end of the file
Close files: int fclose (file *f);
Buffer (cache):
why to introduce buffers:
Because the computer operation of the buffer is much faster than the operation of the disk, in order to improve the efficiency of the computer, when we read the information from the disk, the first to put the read data in the buffer, the computer and then directly from the buffer data, and so on the buffer after the data taken out of the disk to read, This reduces the number of reads and writes to the disk.
Defined:
A buffer is an area of memory that is used between input and the CPU to cache data. It enables low-speed input and high-speed CPUs to work in a coordinated manner, avoiding low-speed input that occupy the CPU and freeing the CPU to work efficiently.
Type of buffer:
full buffering (_IOFBF): Actual I/O operations (disk files) when the standard I/O cache is filled
row buffering (_IOLBF): Performs a true I/O operation when a newline character is encountered in the input output. However, when the buffer is filled, the actual I/O operation is performed even without a newline character. (Standard input stdin and standard output stdout)
without Buffering (_IONBF): Without buffers, data is immediately read into or output to external memory files or devices. If the standard error stdeer
FILE structure Body and buffer