CS 12 - Lab 3
In this lab you will write functions that simulate some of the C++ String
handling functions. You should read section 5.12 starting on page 343
of the textbook before coming to lab. You might also want to do exercises
5.21 and 5.22 on pages 378-379.
The Functions
Write your own version of the following functions:
- strcpy (call it cs12strcpy)
- strncpy (call it cs12strncpy)
- strcmp (call it cs12strcmp)
- strncmp (call it cs12strncmp)
- strlen (call it cs12strlen)
Each of these functions is described on pages 346-347 of the textbook. Your
function signatures, except for the names, must match those given in the book.
For example, the signature for strcpy is:
char *strcpy( char *s1, const char *s2 );
Therefore, the signature for your function will be:
char *cs12strcpy( char *s1, const char *s2 );
You are not allowed to use any of the standard C++ functions in any
of your functions.
Testing
To test your functions, write a main program to test them. The program should
call each function at least twice. You will need to declare at least
one character array for this (probably more). Make sure you declare an actual
array and not a pointer. In other words, you should have a declaration such
as:
char string[ 80 ];
Grading
When you have finished the program, your TA will grade it. To receive full
credit, your TA will check all of the following:
- Each function is tested by being called from your main program at least
twice and works correctly.
- Each function is properly commented, including a comment stating what
the function does, what it returns, and what each of its parameters
are for.
- The program is well formatted (i.e. style). For example, you should
be consistent with your indenting in the program.