Programming in C
Autumn 2009

Grading of the course exam

Question 1: Function trans

Most of the students have done this very well.
For checking that sting is not NULL 2 p
Coping of a string 10 p

Question 2: Linked list, insertlist and deletelist


Grading:
  The question required you to declare data types needed for
double-linked list
  with header node.

  - Correct declaration for structures.
  -> Max 3p 

  Next you were asked to write function insertList. This required to
allocate
  memory for new list node and insert that node to correct position
inside list.
  To search the correct position you have to traverse trough the list
and
  compare node values to value you are inserting.
  Inserting requires to update pointers in your nodes in order to
  preserve linked structure. Also links in your header node must be
updated if
  necessary.

  - Parameters passed as required, return values are correct
  - Memory allocation done correctly; possible errors checked
  - Insertion updates linked structure between nodes correctly
  - Header node links updated correctly
  -> Max 5p

  Then you had to write function deleteList to free the list.

  - Parameter passed to function is pointer to list
  - Deletion works correctly for both empty and nonempty lists
  - All nodes freed, no memory lost
  -> Max 4p

  Last thing to do was to give an example, how to use your deleteList
function
  to delete a list.

  - Example
  -> Max 1p

  Last point available was granted if the answer given was written in
good programming style.

  - Use of good variable names
  - No unnecessary code
  - Comments about what your functions does
  -> Max 1p

  Total maximum: 14p

Question 3: Program filelength

Answers to question 3 have been graded as follows:

- Proper inclusion of header files (2 p)
- Proper use of command line arguments (2 p)
- Definitions and correct initialisations of variables (2 p)
- Opening of files (2 p)
- Calculation of file size (2 p)
- Determining and displaying the largest and smallest files (2 p)
- Cleaning up (2 p)

In general, the solutions were quite good, although many of them
were more complicated than necessary.

Common mistakes:

Many solutions assumed that if the user doesn't provide command line
arguments, the value of argc is 0. It is actually 1 because the name
of the called program is located in argv[0].

Another common error was to use the assignment operator where
equality comparison was intended. This affected the grading because
it may result in erroneous code that can still be compiled.

Most solutions calculated the length of the input file by increasing
a counter after each successful call of the fgetc function. This
approach was accepted. However, a cleaner approach uses fseek
function to locate the end of file and then uses the ftell function
to determine the file position.