Computer Science 3510
Summer 2000
Exercise 1

Note. This is a small programming exercise to let you flex your muscles. It is not one of the major programming assignments.

Due: Monday, May 21, 5:00pm.

Write two functions that work on null-terminated strings. Contracts and prototypes for them are given below. Test each function carefully using a testing program that you write. Use a tester that runs unattended. It should not require any input from the user. Ideally, it should check its own results. For example, use mystrdup to duplicate a string, and then use library function strcmp to see whether the duplicate has the same characters in it as the original.

Mystrdup

////////////////////////////////////////////////////////////////
// mystrdup(s) returns a pointer to a copy of null-terminated //
// string s.  The copy is allocated using new.                //
////////////////////////////////////////////////////////////////

char* mystrdup(char *s);

Mystrchr

//////////////////////////////////////////////////////////////////
// mystrchr(s,c) searches for the first occurrence of character //
// c in null-terminated string s.  It returns a pointer to      //
// that first occurrence.  If character c does not occur in     //
// s, then strchr returns NULL.                                 //
//////////////////////////////////////////////////////////////////

char* mystrchr(char *s, char c);