\documentclass[12pt]{article}
\topmargin -10.8truemm
\textheight 218truemm
\oddsidemargin 0.0truemm
\evensidemargin 0.0truemm
\textwidth 165truemm
% remove all page numbers
\renewcommand{\thepage}{\mbox{}}
\begin{document}
\begin{center}
{\Large CSc 265---F96---Quiz 3 (Time: 20 min.)}
\end{center}
%
\begin{tabbing}
Student name:1\=\underline{\hspace{3in}}1\=Lab Section:1\=\kill
Student name:\>\underline{\hspace{3in}}\>Lab Section:\>\underline{\hspace{.75in}}
\end{tabbing}
%
\noindent{\bf Note}:
\begin{itemize}
\item
String $p$ is a {\it prefix\/} of string $s$ if
$s$ consists of $p$ followed by zero or more characters.
For example, \verb+""+, \verb+"ab"+ and \verb+"abcd"+ are prefixes
of \verb+"abcd"+; \verb+"bcd"+ and \verb+"ba"+ are not.
\item Assume \verb+shift+ and \verb+prefix+ satisfy the
specifications shown on the overhead.
\end{itemize}
%
\begin{enumerate}
\item (3 points)
Write the {\it exact output\/} of the program shown below.
The function \verb+sub+ is shown in question 2.
{\footnotesize\begin{verbatim}
main() {  char s[100];
          strcpy(s,"0123456789");
          sub(s,"123","ab");
          printf("sub: %s\n",s);
}
\end{verbatim}}
%
\item (7 points)
Inspect the implementation of \verb+sub+ carefully.
For each fault found, provide the line number and a brief description
(no more than 10 words) of the fault.
{\footnotesize\begin{verbatim}
/* if s contains old then
*     replace the leftmost occurrence of old in s by new
*     return 1
*  else
*     leave s unchanged
*     return 0
*/
int sub(char* s, char* old, char* new) {
        int i,j,oldLength,newLength;

        oldLength = strlen(old);
        newLength = strlen(new);
        for (i = 0; i < strlen(s)-oldLength; i++) {
                if (prefix(&s[i],old)) {
                        shift(s,i+oldLength,newLength-oldLength+1);
                        for (j  = 0; j < newLength; j++)
                                s[i+j] = new[j];
                        return 1;
                }
        }
        return 0;
}
\end{verbatim}}
%
\end{enumerate}
%
\end{document}
