I'm trying to write a function that will return the reverse of a character array or string. Here's how I want everything to work out:
1). The user is asked for a string/character array.
2). The user enters a string/character array (the size is unknown until the user enters the string/character array, so I'm not sure how to set up the memory allocation).
3). The function reads the string/character array and reverses it. So if the user enters, "this is my test" the function will return "tset ym si siht".
I can't figure out any way to do this other than to create a string or character array and copy one letter at a time from the user input into the reversed string/character array. Unfortunately, I can't seem to figure out how to copy a single character from one string into another.
Here's the code I have so far:
******************************************
string ReverseString(string input){
int length = input.length();
string rString = "\0";
for(int i = 0; i<length; i++)
// CODE HERE THAT WILL
// COPY ONE CHARACTER FROM
// INPUT INTO rString
return rString;
}
******************************************
Thanks in advance!