CS 61C (Fall 2007)

Quiz 3

One question, submit as "quiz3".  Due 2:45pm before lecture 9/5/2007.


To be very clear, you should submit one and only one file template.txt which contains your answers, by running submit quiz3.

1.

Consider the following definition of append.
1 )  /*
2 )     Return the result of appending the characters in s2 to s1.
3 )     Assumption: enough space has been allocated for s1 to store
4 )     the extra characters.
5 ) */
6 ) char* append (char s1[ ], char s2[ ]) {
7 )     int s1len = strlen (s1);
8 )     int s2len = strlen (s2);
9 )     int k;
10)     for (k=0; k<s2len; k++) {
11)         s1[k+s1len] = s2[k];
12)     }
13)     return s1;
14) }
The code has a major bug in it. On which line number does the bug occur? Explain what the bug is, and/or how to correct it.