Creating a file of unsorted names
Now that we have getoptFiles.c
, we can use it as a starting point for our next sequential file program, createUnsorted.c
. This program will be used to create a file of names, one name on a line, that will later become input to the sortNames.c
program.
In createUnsorted.c
, we will repeatedly read in a single name and write it out. We can test the functionality of this program by using stdin
and stdout
as well as reading and writing files.
However, before we can go further, we need to consider the issue of dirty input data. We can assume that a name begins with alphanumeric characters and ends with alphanumeric characters; we will assume that anything in between is part of the name, however odd it may appear. What happens if the user enters whitespace either before or after the name? Or if there is whitespace both before and after the name? Recall also that fgets()
ends its input...