- Write a
myStrlen
function which is the same as the library strlen
function.
Assume the prototype is
int myStrlen(char a[]);
int myStrlen(char* a);
- Write the
myStrcpy
function which is the same as the library strlen
function.
Assume the prototype is
void myStrcpy(char a[], char b[]);
void myStrcpy(char* a, char* b);
- Write the
myStrcat
function which is the same as the library strlen
function.
Assume the prototype is
void myStrcat(char a[], char b[]);
void myStrcat(char* a, char* b);
- Write the
myStrcmp
function which is the same as the library strlen
function.
Assume the prototype is
int myStrcmp(char a[], char b[]); // array version
int myStrcmp(char* a, char* b); // pointer version
For example,
i = myStrcmp("abc", "after"); // result is a negative value
There is a slight twist to this problem. The standard allows each compiler
to decide if the char
type is signed or not, so the range of
of a char
is either -128..127 (signed) or 0..255 (unsigned).
To do the comparison properly, the comparison should be done on the
unsigned characters, which requires casting to that type.