COMP1511 17s1 Introduction to Programming
  1. Your tutor has asked a lab pair to present their week 10 work.

    Discuss the good, the bad and the ugly aspects of their code.

    Please be gentle in any criticism - we are all learning!

  2. Did you blog last week? What is this week's blogging theme?
  3. How are we progressing with the assignment?

    Have we learnt anything we think would be useful to share with the tutorial?

  4. Define a struct student which your tutor could use to store lab grades for a COMP1511 student.

    Include appropriate #defines.

    Include a field allowing a linked list to be formed from student structs.

  5. Assume you have a function with the following prototype
    struct student *read_student(FILE *stream)
    
    which mallocs a student struct and assigns values to its fields, from values read from a line of the stream, it is given as an argument.

    Write a function with this prototype:

    struct student *read_students_file(char filename[])
    
    which opens the file it is given as argument and calls read_student to create student structs containing the information in the file.

    read_students_file should return these student structs as a linked list.

  6. Write a function with this prototype:
    struct student *read_student(FILE *stream)
    
    which mallocs a student struct and assigns values to its fields from values read from a line of the the stream it is given as argument.

    The file will contain lines specifing zid, student name, lab name and lab grades in this format:

    5099703 Tsun Bordignon thu13-sitar A+A+CABAB..A.
    
    read_student should return a pointer to the newly created student struct, or NULL if it can not read a line.

    Revision questions

    The remaining tutorial questions are primarily intended for revision - either this week or later in session.

    Your tutor may still choose to cover some of the questions time permitting.

    • Write a C function splitString which takes a string read by fgets containing substrings separated by commas, places the substrings in an char[][] array and returns the number of strings.

      You can assume there at most 128 words on the line and no word is more than 32 characters long.

    • Write a C function printSubstrings which prints one per line the substrings in the char[][] array created in the previous question.
    • Write a C function substringsSorted which given the char[][] array in the previous question returns 1 if the substrings are increasing order and 0 otherwise.
    • Write a C function searchSubstrings which given the char[][] array in the previous question returns 1 if the array contains a specified string and 0 otherwise.
    • Write a program substring.c which reads lines using fgets and calls the above functions.