Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So my CS professor gave the whole class a simple assignment. \"Write a recursive

ID: 654336 • Letter: S

Question

So my CS professor gave the whole class a simple assignment. "Write a recursive function that will swap the order of a section in an array of chars." I thought to myself, "Easy. I'll finish this up in about 5 minutes and I'll get to work on my Trig homework before I leave."

This is not what happened. An hour later, the professor and I are both wondering what on Earth is going wrong.

#include<iostream>
void swap(char charList, int start, int stop);

int main()
{
    char myList[] = {'a', 'b', 'c', 'D', 'E', 'F', 'g', 'h', 'i', 'j'};
    int size = 9;
    printCharList(myList, size);
    swap(myList, 3, 5);           //<--- It doesn't seem to like this call
    return 0;
}

void swap(char charList[], int start, int stop)
{
    char temp
    if(start < stop)
    {
        temp = charList[stop];
        charList[start] = charList[stop];
        charList[stop] = temp;
        swap(charList, start+1, stop-1);
    }
    else
        std::cout << "start > stop ";
}
The code is stupidly simple, so you can imagine my confusion when it refused to compile. It keeps throwing up an error message suggesting that I am trying to convert a pointer to a char, but I'm almost positive that I've done no such thing. I'm sure the problem is right in front of my face, but I have had no luck in finding it. Could you help a guy out?

Explanation / Answer

In the header, you declare the signature as

void swap(char charList, int start, int stop);
you probably want to declare it as

void swap(char charList[], int start, int stop);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote