Chapter 23: Using File Input and File Output
In the previous chapter, we introduced many basic file concepts as well as most of the file manipulation functions. We also demonstrated a simple way to open and close files.
In this chapter, we will put that knowledge to better use by developing programs to read and write to/from a sequential file. Our goal in this chapter is to accept input from a console or a file, sort each line in a file, and then write out the result, either to a console or to a file. We will find that there are several subtleties that we will need to address; we will also be using nearly every C skill we have learned so far.
The following topics will be covered in this chapter:
- Creating a template program to process filenames given on the command line
- Creating a program to accept input from either
stdin
or a file and write output to eitherstdout
or a file - Creating a function to trim input from
fgets()
- Creating...