Computational Physics
Weeks 5/6 Course work
Comments and questions to John Rowe.
You will probably want to use the code examples in the notes
as the basis for your work, these can be cut and pasted from
the Web pages at
http://newton.ex.ac.uk/teaching/resources/jmr/.
This is two week's work and may be handed in as a single piece of
work.
- Take the skeleton address-book program from the "functions"
notes and do enough to make it compile but not do anything, (ie #define some constants in a header file and write
some dummy functions that do nothing but print "You've called this
function". You will need to put the function prototypes in the header
file).
- Now write the get_user_command function,
making sure either thaat it only returns valid values or
that main() handles invalid values correctly..
- Decide on a suitable structure for a phone-book entry and define
it, together with a next member, in the header
file.
- Now add the add_new_phonebook_entry
function basing it on the newcoord function from
today's notes. (NB, you will need to declare a pointer in
main to act as the start of the list - don't
forget to initialise it to NULL!).
- Now add a simplified version of lookup_phonebook_entry which just goes through the
whole linked list printing out every entry.
- The function strstr(haystack, needle)
(where both haystack and needle are strings) returns non-zero when the first
string contains the second, eg
strstr("Football", "ball") is true
but strstr("Football", "Leeds Utd.") is
false.
Modify your lookup_phonebook_entry
function to read in a search string and just print out the entries
that match. (You will need to
#include <string.h>).
Is strstr case-sensitive?
- What happens if the search string is blank (ie you just hit
<return>)?
Submit this in
two weeks time.