Homework: Debugging C

Due: Monday, October 28, 2024, at 11:59pm

Jump To:

Goals
Synopsis
Set-Up
Tech Requirements
Code Quality
Assessment
Turn-in instructions

Assignment Goal

In this assignment you will practice your debugging skills using gdb and valgrind. Additionally, you will gain more experience working with C, using multiple module files, and some common Linux tools.

Synopsis

This assignment asks you to exercise debugging skills. In particular, you will need to finish the implementation of a Dictionary module that can perform look-up operations, and a driver program that uses the module to generate English statistics about a given English text.

For this homework, we will provide you with code that already has most of the desired functionality, but is full of nasty memory errors. Your job is to understand how memory is managed and used in the provided code, identify those errors, and come up with a solution to those errors.

This project should be done independently. If you work with a classmate, make sure you are each editing and working on your own set of files. You should not copy and paste code.

Set-Up

Before you get started, ensure that your set-up is up-to-date and appropriate.

  1. You should do this assignment using cancun, including gcc
  2. You should have already set up your local copy of your personal git repository, and added the upstream repository cse374-materials. If you are having trouble with your repositories, or have not yet completed HW3, please return to HW3 and follow directions for this set-up.
  3. Ensure that your repository is up-to-date and committed. (You can use git status to determine if there are outstanding changes, and git add and git commit if you are unsure.)
  4. Use git pull upstream main to pull the newest commit from the upstream repository. This will give you access to the hw4 folder containing the materials for this assignment. (upstream specifies that you want to pull from the upstream repository, and main specifies the branch. You may see a text editor open to allow you to edit the merge message. This will likely be Vim, so you can edit it and then save, or just accept the current text and exit using :q!.)

You will do this assignment in your new hw4 folder. You should get into the habit of committing and pushing code frequently.

Technical Requirements

This homework implements a program that has the basic functionality of checking spelling of English text and outputting relevant statistics on the number of words, paragraphs, typos, etc.. This program is case insensitive, so it will recognize “Hello” in the input text as “hello” in the dictionary.

The flow of the program, in general, goes like this:

The provided code already has most of the functionality, but is full of nasty memory errors. And your job is to understand how memory is managed and used in the provided code, identify those errors, and come up with a solution to those errors.

Goal

In the end, the program needs to satisfy the following requirements:

Starter Code

Your hw4 folder contains the following files:

The only files that you’ll need to modify and submit are:

Although there are only two files that contain the buggy code, you’ll still want to look into the header files to see what each function is supposed to do, and to decide how you may modify the code while satisfying the spec. In C programming header files specify the function signatures and provide information about the interface to their corresponding modules.

In the SpellChecker.h, there is a line typedef char** Dictionary;. We will talk more about typedef this week, but note that the Dictionary is of type char**.

Notes about Data Types

This homework involves usage of some types that we’d like to address before you look at the actual code: