\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage[left=1in,right=1in,top=0.75in,bottom=0.5in]{geometry}
\usepackage{url}
\usepackage{amsmath}
\usepackage{upquote}
\pagestyle{myheadings}
\markright{MAT 4370: Programming Assignment 8}

\long\def\symbolfootnote[#1]#2{\begingroup%
\def\thefootnote{\fnsymbol{footnote}}\footnote[#1]{#2}\endgroup} 

\begin{document}
\thispagestyle{empty}
\begin{center}
  {\Large MAT 4370: Programming Assignment 8}\\
  Due: Friday, March 1
\end{center}

\section*{The Problem}
We would like to implement a ``poor man's'' version of the Unix
\verb!sort! utility.  Working on this program will consolidate your
understanding of the following ideas:
\begin{itemize}
  \item Processing strings
  \item Processing command line arguments
  \item Reading streams of data: line-by-line and character-by-character
  \item Allocation of memory via \verb!malloc()!
\end{itemize}
Our implementation is going to be relatively simple, in the following
ways:
\begin{enumerate}
 \item The synopsis for our sort is:  
\begin{quote}
\verb!./pmsort filename!
\end{quote}
There will be just one command-line argument, which names the file of
data to sort.  Your program should verify that the correct number of
arguments has been provided and that the specified file exists.
Appropriate error messages should be provided.

\item We will assume the file has at most 1000 lines, with one word
  per line.  Each word is assumed to be at most 10 characters in
  length.  However, your program must still check that these
  assumptions apply and do something reasonable if either limit is
  exceeded.

\item Unlike the Unix utility, your sort program will not have any
  command-line switches.  Instead, we will just sort according to how
  \verb!strcmp()! compares strings.

\item Unlike the Unix utility, your sort algorithm does not need to be
  sophisticated.  Since selection sort is among the easiest sort
  algorithms, use that.  The time you save thinking about sorting can
  be invested in system-related tasks:  opening and closing streams,
  reading streams, setting up an \verb!argv!-like structure, using
  \verb!malloc()!, etc.  

\end{enumerate}

\section*{What to Do}
\begin{itemize}
\item Read the Unix \verb!man! page for \verb!sort!.  Try it out on a
  simple text file.
\item Study the three sample stream programs discussed in class.
  Refer to the appropriate sections in the book to reinforce your
  understanding of these programs --- file i/o has a number of
  important subtleties!
\item Compile and execute each of the three sample programs.
  Experiment with each to see if they behave the way you think they
  should.
\item Re-implement the \verb!readLine()! function so that it no longer
  makes use of \verb!fgets()!.  Instead, process the input on a
  given line character-by-character.
\item Provide code which will create a data structure similar to
  \verb!argv! to hold all of the words to be sorted.  Use
  \verb!malloc()! to ensure that each entry has just the required
  number of bytes needed to store the words.  The final entry in your
  array should be the \verb!NULL! pointer.
\item Implement a \verb!sort()! function which will rearrange the
  words in sorted order.  To swap two words in your array, note that
  only a pair of pointers need to move.  The strings themselves, once
  established, will never move.
\item Put all the pieces together to form your sort utility. Carefully
  test your program to ensure it behaves correctly.
\end{itemize}


  

\section*{What to Submit}
When your sort implementation works to your satisfaction,
place it in a folder named {\tt hw08}.  (Source code only please; no
other files need to be submitted.) Drag this
folder onto the SUBMIT icon, found in the Applications folder.


\end{document}
