O'Reilly logo

C Pocket Reference by Ulla Kirch-Prinz, Peter Prinz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Input and Output

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 type FILE 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 subsequent operations.

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:

stdin

The standard input device

stdout

The standard output device

stderr

The standard output device for error messages

stdin is generally associated with the keyboard, while stdout and stderr are 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 file position , 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required