I/O Streams
Explore how to use input and output streams in C to handle data from keyboards, files, and devices. Understand standard streams, formatted input/output with printf and scanf, and character-based I/O for efficient program interaction.
Streams in C
The standard C library (linked to using #include <stdio.h>) includes a handful of functions for performing input and output in C.
C and UNIX make use of a concept called streams in which data can be sent and received between programs, devices, and the operating system. We can distinguish between two types of streams, text and binary.
- Text streams are made up of lines, where each line has zero or more characters and is terminated by a newline character
\n. - Binary streams are more ‘raw’ and consist of a stream of any number of bytes.
C programs all have three ‘built-in’ streams: standard input, standard output, and standard error. Here are some examples of how standard input and standard output streams are used:
-
When we interact with a C program in a terminal and type values in to pass to the program, we ...