the function is void, so doesn't return a value. The output can only be through the cout and there is only one that only outputs an empty string, so, what should the cout contain?
Note: I'm assuming you are NOT allowed to do this, but if the code was correct, I would format it like
if (v == '\0') interleave (v, w+1);
else if (w == '\0') interleave (v+1, w);
else cout << "";
Yeah, your answer is ******. Did you test it?
Write a recursive function
void interleave(const char *v, const char *w) ;
that outputs the characters in v and w interleaved, starting with *v.
If you reach the empty string for either parameter , then output the other parameter .
As usual, no loops, but you may define one or more helper functions.
Example interleave("abcd", "xyz") will output axbyczd .
Here is my solution:
void interleave(const char *v, const char *w)
{
if(v == '\0')
{
interleave(v,w+1);
}
else if(w == '\0')
{
interleave(v+1,w);
}
else
{
cout << "";
}
}
This should be the correct answer, but MyProgrammingLab is not accepting it. Is there something that I need to add or change in this function?