Main Contents Page
CTEC1401 Programming in C
Quick Reference
Week 16: Functions I
Week 17: Functions II
Week 18: Functions III

Incremental Development of a String Library

Copy the source code from strlib.c into a text editor and save it as strlib.c.

This provides you with the basic program structure, including a main function that acts as a test harness. Note how the program

  1. Initial Compile

    Compile the program and run it selecting test option 1. Why do you get results even though the functions have not yet been implemented?

  2. strlength

    Complete the function strlength and recompile strlib.c
    We have provided an implementation for you to use. Uncomment this and make sure you can see why it works.
    Try the following input strings to check that the function works (note that the last input string in the table is the empty string)

    Input String   Expected length
    hello5
    0123 4567 8912
     0
  3. strisalpha

    Complete the function strisalpha and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the strisalpha test for each of these inputs.

  4. strfirst

    Complete the function strfirst and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the strfirst test for each of these inputs.

  5. strlast

    Complete the function strlast and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the strlast test for each of these inputs.

  6. strcopy

    Complete the function strcopy and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the strcopy test for each of these inputs.

  7. strhead

    Complete the function strhead and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the strhead test for each of these inputs.

  8. strtail

    Complete the function strtail and recompile strlib.c
    What input test data do you need to check that it works?
    Run strings again selecting the strtail test for each of these inputs.

  9. strmid

    Complete the function strmid and recompile strlib.c. Your function should make suitable checks on valid values for start and end and adjust the result appropriately.
    What input test data do you need to check that it works?
    Run strlib again selecting the strmid test for each of these inputs.

  10. strnodup

    Complete the function strnodup and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the strnodup test for each of these inputs.

  11. isprefix

    Complete the function isprefix and recompile strlib.c
    What input test data do you need to check that it works?
    Run strlib again selecting the isprefix test for each of these inputs.