Input and output

A program has to interact with the outside world to be said to be doing anything. traditionally this has meant reading in text and writing it out. Input and output can be thought of as using devices such as keyboards and screens or as coming from and going to files, which are named areas stored by the operating system.

C does not usually distinguish between these two concepts. In fact the language itself has no pre-defined input or output operations. Instead, a standard library of input and output functions are defined and can be made accessible by including the library header file stdio.h.

All input comes from and all output goes to files. By default the files stdin and stdout are the keyboard and the screen, which to the C program appear as files.

There is a third default file, called stderr which carries the stream of warnings and error messages from running C programs to the screen.

For the moment we only consider input and output using stdin and stdout. It is usually possible to attach files to these when running a programming, using redirection or pipes.

Exercises on this section.


Output.

Input.

Format specifiers.


Next - user defined types.


Back to Contents page.