UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

Chapter 8.  Input and output functions

8.1.  Introduction

The C language provides a set of library functions to perform input and output (I/O) operations. Those functions can read or write any type of data to files.

In C, a file can refer to a disk file, a terminal, a printer, etc. That is, a file represents a concrete device with which you want to exchange information. The C language treats a file as a series of bytes (or characters). These series of bytes, which are what is really transferred between the file and a program, are called as a whole as a stream.

Before you can operate on the file, you have to open that file. In C there are 3 file streams that are pre-opened for you - that is, they are always available for use in the programs.

  • stdin: The standard input for reading. Usually it links to your keyboard.

  • stdout: The standard output for writing. Usually, it points to your terminal screen.

  • stderr: The standard output for writing error messages. Usually, it also points to your terminal screen.

In the following sections we will see different ways to use stdin and stdout. The functions we are going to see need the stdio.h library to work.