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?
Main Contents Page | CTEC1401 Programming in C |
Quick Reference |
Week 16: Functions I | Week 17: Functions II |
Week 18: Functions III |
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
main
more readable;switch
statement to allow the functions to be
tested selectively.Compile the program and run it selecting test option 1. Why do you get results even though the functions have not yet been implemented?
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 |
---|---|
hello | 5 |
0123 4567 89 | 12 |
0 | |
strisalpha
and recompile strlib.c
strlib
again selecting the strisalpha
test for each of these inputs.
strfirst
and recompile strlib.c
strlib
again selecting the strfirst
test for each of these inputs.
strlast
and recompile strlib.c
strlib
again selecting the strlast
test for each of these inputs.
strcopy
and recompile strlib.c
strlib
again selecting the strcopy
test for each of these inputs.
strhead
and recompile strlib.c
strlib
again selecting the strhead
test for each of these inputs.
strtail
and recompile strlib.c
strings
again selecting the strtail
test for each of these inputs.
strmid
and recompile strlib.c
.
Your function should make suitable checks on valid values for start
and end
and adjust the result appropriately.strlib
again selecting the strmid
test for each of these inputs.
strnodup
and recompile strlib.c
strlib
again selecting the strnodup
test for
each of these inputs.
isprefix
and recompile strlib.c
strlib
again selecting the isprefix
test for
each of these inputs.