CITS2002 Systems Programming  
 

Unit home

Final exam

help2002

Lecture & Workshop
recordings on LMS

Schedule

FAQ

C textbooks

OS textbooks

Information resources


Extra reading

Past projects

Recent feedback


Working effectively

Look after yourself!

Solutions for Labsheet 5 - for the week commencing 25th September 2023

This page provides some sample solutions and discussion on some of the tasks of Labsheet-5.

Tasks

  1. Write a C program, named listints, which will print the integers requested via a single command-line argument. The list of integers is to appear in strictly increasing order, with each requested integer appearing once and only once (even if duplicated in the request).

    A sample solution: listints.c

  2. Locate a single-file program consisting of several functions, such as the one developed in Workshop-3.
    Now, break the single-file program into a multi-file project consisting of:

    • a single C header file (providing the function declarations), and
    • several C source code files (with each C file providing at least one function definition).

    Next, develop a simple Makefile, as introduced in Lecture-17, to compile and link your multi-file project using make.
    Determine how to test that your Makefile correctly represents the dependencies between your source and header files.
    Extend your Makefile by adding a new target to cleanup (remove) any unnecessary files (careful!).

    A sample solution: haversine-project.zip

  3. Both Linux and macOS provide a standard command named wc (an abbreviation for wordcount!) which determines the number of lines, words, and characters in a named file. You can read about this command using the online documentation: (man wc).

    For this task, you will develop your own version of the wc program named mywc.

    A sample solution: mywc-basic.c

  4. 🌶 Now, using the standard getopt() function introduced in Lecture 17, add support for command-line options to your mywc utility from Task-3.

    Add command-line options to request:

    • -c to report the number of characters,
    • -l to report the number of lines,
    • -L to report the maximum line length (as supported on Linux, but not macOS), and
    • -w to report the number of words.

    A sample solution: mywc-getopt.c

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Presented by [email protected]