A stream is the means of transferring data, specifically bytes, between any device and a program. Streams are device-oriented. Devices, as we have seen, include a keyboard and screen. These are associated with the stdin and stdoutpredefined streams. A file is an abstract data storage device. Other devices include hard disks, Solid-State Drives (SSDs), printers, Compact Discs (CDs), Digital Video Discs (DVD), and magnetic tape devices.
For the movement of data—that is, a stream—to exist, there needs to be a connection from one device to the program to be opened for the data transfer to take place. When we run a C program, the connections to stdin, stdout, and stderr have already been made by the C runtime library for us. For any other kind of stream, we must explicitly make that connection and open a stream.
C supports two types of streams—a text stream and a binary stream. A text stream consists of lines of bytes,...