Hey everyone,
I have to manipulate two functions RECURSIVELY, strlen and strcpy.
I was able to code the strlen:
int length(char* str){
if(str == NULL){
return 0;
}else{
return length(str, 0);
}
}
int length(char* str, int l){
int len=0;
if(str[l]){
len = length(str,l+1);
} else {
return l;
}
return len;
}
But I am having a lot of trouble with even beginning the strcpy function:
char copy(char* old_str, char* new_str){
if(old_str == NULL){
cout << "Could not copy, string is empty\n";
return -1;
}else{
}
}
Here is my input on Strcpy:
- The base case can return -1 because you shouldn't have to copy nothing over to a new string.
- For the Recursive call, I have to go through the old_str recursively.
I appreciate all of the help.
Thank you.
-Ben