What is a file? "File" is a unit that stores information exchange information inside and outside the computer refers to a collection of data stored on the external medium, whether it is a character or thousands of records, to be stored and processed in a file. In memory, all files must be stored in binary forms, and binary files can communicate directly with memory without conversion. The C language looks a file to make a byte sequence, which consists of a series of bytes, called "stream stream", access in bytes, and has no recorded boundaries.
File Category: First, the media supplied according to the file: disk file, tape file, memory file, device file. Second, according to the content: source program file, target file, data file. Third, press the operating system to read and write the disk file: buffer file system and non-buffer file system. Buffer file system: Operating system opens up a read and write buffer for each file in memory. Fourth, press the data organization form: ANSII code file and binary file ansii file: also called text file, each byte stores an ANSII code, represents a character. Output with the ANSII code form corresponds to the character, one byte represents a character, so it is easy to process characters one by one, which is also easy to output characters. However, generally accounted for many storage space, and spend conversion time (transition between binary and ANSII). Binary file: Put the data in the file in the stored form in memory to the magnetic disk. Advantages: The occupied storage space is small, the file form and memory form are consistent, and no conversion is required, and thus the speed is fast.
File Type Pointer: To call a file, you must know the information related to this file, such as file name, file status, file current read and write position, with the memory buffer address corresponding to the file, the buffer unprocessed string , File operation mode and other information, which is stored in a structural variable, which is defined by the system, named file. Typedef struct {short level; // buffer 'full' or 'empty' degree Unsigned flags; // file status flag char fd; // file descriptor file number unsigned char hold; // If there is no buffer area is not read Character short bsize; // buffer size unsigned char * buffer; // data buffer location unsigned char * curp; / / pointer, current point to unsigned istemp; // This file is a temporary file Short token; // Validity check} file; when processed a file, you need to define a file type pointer to create a pointer variable of a FILE type, which is used to point to a File type structure in the system memory (ie File information area). When the program starts running, the system automatically opens three standard files: standard input, standard output, and standard error output, usually the three files are connected to the terminal. Therefore, we used the terminal input or output we used to open the terminal file. The system also defines three file pointers: stdin, stdout, stderr points to them.
Usage in Example: First, Fopen (), Fclose (), FGETC (), FPUTC (): #include
* / / * Copy a disk file to another disk file * / # include