Topics CoveredCustomizing the command prompt in Windows
Standard input and output
Getchar(), putchar(), Pipes
Watch Video Part 4a >>
Watch Video Part 4b >>
Exercises1. Using the Pseudocode provided (in2out.txt) and the descriptions of the functions getchar() and putchar(), construct a C program in2out.c which copies each character from standard input into its standard output.
2. Try to run in2out with various redirection operators. Redirect input to come from a file, or redirect output to go to a file, and try both together. Try using in2out in conjunction with the "pipe" `|' operator.
3. In a previous part we made the program fahr.c to convert a range of temperatures given at the command line. Run this program with the following parameters: fahr.exe 0 300 20 . Fahrenheit temperatures from 0 to 300 should appear increasing in steps of 20. What happens if you run fahr.exe 300 0 20 ? Make appropriate changes to fahr.c such that it works in the forward direction as well as in the backward direction. That is, fahr 0 300 20 should provide a normal temperature table and fahr 300 0 20 should provide a table going backwards from 300 down to 0, decreasing in steps of 20.
Questions1. Run the program in2out without any redirection operators. Any input typed at the keyboard will be echoed to the screen. One way to end this program from the keyboard is to signal the end of file with the Ctrl-Z keyboard shortcut. What other ways can you find to end this program (without closing the command prompt)?
2. Look up the manual page for the function getchar(3). When we write getchar(3), we mean the manual page section 3 of getchar. This function reads a single character, but its return type is int. Why do you suppose the return type was defined as int rather than as char, as might be expected?