Lab 7: Strings and dynamic allocation in C

The goal of this lab is to practice working with pointers, dynamic allocation, and strings in C.

You will write some functions for a "homemade string" library that works like the standard C library's functions for manipulating arrays of characters as strings.

1. Set up

Clone the repository to get the code for this lab:

hg clone /cslab/class/csci245/lab7

Now you can cd into the lab7 directory.

2. Inspecting the code

What you have are the header file and implementation for our "homemade string" library. Consider the two functions that are written for you:

Take a moment to draw some pictures. How many characters are required to hold the string "Example"? What would the length of that string be?

You can compile the example program with make. That will compile the example program in hmstrexample.c, which you can run with ./hmstrexample. The command ./strexample will run an equivalent program that uses the standard C library functions. Those two programs should produce the same output--once you complete this lab.

3. Implementing the remaining operations.

4. Testing your code

I have provided a makefile to compile your code and two driver programs.

Running make will compile hmstring.c and will also produce the executable for hmstrexample, which runs various tests on your functions. As supplied, this program and strexample should produce the same output once your functions are complete.

Feel free to add other tests/examples to hmstrexample.c.

5. Turning it in

Make sure that you have added your names to the comment at the beginning of hmstring.c. Also be sure that you have all of your work committed to Mercurial. Then do
make handin
to get it handed in. Check for a message indicating success, and make sure that the revision submitted is your latest code.
Thomas VanDrunen, Cary Gray
Last modified: Thu Mar 21 12:15:53 CDT 2013