CSc 201/202
Coursework for C/C++ Course
Part 1: Programming with C
(40% of the C/C++ Coursework
Due Friday Week 1 Lent Term)
As discussed in weeks 6 and 7, functions are at the heart of code reuse in C. The include file
string.h provides functions to manipulate string data. The most commonly used functions of these are:String Copy
char* strcpy(char* dest, const char* src);
Copies the string pointed to by src to that pointed to by dest. Returns dest. Leaves the string pointed to by src unchanged.
String Concatenation
char* strcat(char* dest, const char* src);
Appends a copy of the string pointed to by src to the end of the string pointed to by dest. Returns dest. Leaves the string pointed to by src unchanged.
String Compare
int strcmp(const char* s1, const char* s2);
Returns an integer greater than, equal to, or less than zero depending on whether the string pointed to by s1 is greater than, equal to or less than the string pointed to by s2. Leaves the strings pointed to by s1 and s2 unchanged.
String Length
int strlen(const char* s);
Returns the length of the string pointed to by s, not including the terminating null character
Provide four functions with the above-mentioned signature. You must not use any of the string manipulation functions available in
string.h or the C library. You can, however, call one of your own functions within another function. For learning reasons your implementation should be biased to make as much use of pointers and pointer arithmetic as possible.Put all the four functions in a file
myString.h, include this file in your C program. Write a main function to put your string manipulation functions to test. Your program should compile (using gcc or cc) and run on unix.It should also be noted that the source code must be well commented to reflect your understanding of the statements in your program. You can choose to work together. However, acknowledge any such collaboration on your submission.