C语言文件输入输出函数(C language input output function)
C语言文件输入输出函数(C language input output function)
C language file input and output function - basically all!! The 2007-07-05 10:00:09
Classification: C/C + +
C language input and output functions
1. The fopen () function
The fopen function is used to open the file, and its call format is:
The FILE * fopen (char * filename, * type);
In introducing this function; First, learn the following.
(1) stream and file (file)
Streams and files differ in Turbo C2.0, Turbo C2.0 for programmers and access
The backup provides a layer of abstract things called "streams" and the actual device is called a file.
Flow is a logical device with the same behavior. Therefore, the function used to write the disk file is also the same
It can be used to write to the printer. There are two types of streams in Turbo C2.0: text flows (text)
Stream) and binary stream. For disks, it's text files and binaries. this
Software is designed to make it easy for readers to understand Turbo C2.0 language without any special distinction between convection and documentation.
(2) FILE pointer FILE
Actually FILE is a new data type. It's a collection of basic data types for Turbo C2.0,
It's called a structure pointer. The concept of the structure will be described in detail in section iv, where the FILE is understood
For a data structure that includes information about information management, a document must be defined first when opening a file
A pointer.
(3) the function call format introduced in the future will directly write the data type and function return value of the formal parameters
Data type. For example, the function that opens the file above returns a file pointer with the form parameter
Both are character variables (string arrays or string Pointers).
Now let's look at the use of open file functions.
The first formal parameter in the fopen () function represents the file name, which can contain both path and filename.
Such as:
"B: TEST. DAT"
"C: \ \ TC \ \ TEST DAT"
If the path is written as "C: \ TC \