Redirection and Files
Input and output involve functions, data, and devices. Consider, for instance, the echo_eof.c program. It uses the input function getchar(). The input device (we have assumed) is a keyboard, and the input data stream consists of individual characters. Suppose you want to keep the same input function and the same kind of data, but want to change where the program looks for data. A good question to ask (and to answer) is "How does a program know where to look for its input?"
By default, a C program using the standard I/O package looks to the standard input as its source for input. This is the stream identified earlier as stdin. It is whatever has been set up as the usual way for reading data into the computer. It could ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access