In our programs we have been using scanf() to read data from the keyboard. In reality, scanf() is reading data from a file - a special file called stdin which is mapped by the operation system to be the keyboard.
However, in the shell, we can remap the stdin file to be any file:
./a.out < stock4_spv.dat
Similarly, when we print output using printf(), the output has gone to the screen. In reality, printf() is printing to a file called stdout which is normally mapped to the screen. We can capture the output in a different file by mapping the stdout to a different file:
./a.out < stock4_spv.dat > stock_report
A second output file is used by some programs (e.g. the C compiler) to output error messages. This output is written to yet another standard file, stderr, normally mapped to the screen. We can redirect ALL output from a program to a file with:
cc program.c >& temp
This is particularly useful when there are a lot of error messages from the compiler, and we need to see just the first few to fix them.