The ANSI library provides a suite of high-level functions to manage all kinds of input and output, with the appropriate buffering, as uniform data streams.
When a file is opened, for example, a new stream is created along
with a file pointer
, which is a pointer to a structure of
that contains information about the
stream. This information includes the address of the buffer, the
number of bytes not yet read, and other information about the file
itself. The file pointer is used to identify the file in all
Devices such as the display are addressed in the same way as files. When the program starts, three streams are open by default, with the following file pointers:
The standard input device
The standard output device
The standard output device for error messages
stdin is generally associated with the keyboard,
associated with the display, unless redirection has been performed
using the function
freopen() or by the environment
in which the program is running.
There is no predefined file structure in C: every file is assumed to contain simply a sequence of bytes. The internal structure of a file is completely left up to the program that uses it.
All read and write operations are applied at the current
, which is the position of the next
character to be read or written, and is always recorded in the
FILE structure. When the file is opened, the file position is 0. It is ...