C-style character array

I am new to computer programming and have to write a program for class that accepts a line of input and then does character analysis on that input. My program must handle up to 80 characters and display: 1. the input string entered by the user 2. the size of the input 3 the input reversed. I have the first two problems solved but, I am having trouble on the third objective. Any help would be greatly appreciated. Thanks. Here is what I have so far...

#include <iostream> // needed for stream I/O
#include <cstdlib> // needed for system
#include <iomanip> // needed for I/O manipulators
#include <cctype> // needed for c-string
#include <string> // needed for str.length

using namespace std; // simplifies referece cout and cin

void swap (char& v1, char& v2);
// Interchanges values of v1 and v2
string reverse (const string& my_string);
// Returns a copy of my_string in reverse

int main ( )
{
char my_string[81];

system ( "clear" ); // clears screen

cout << "\n\n\tEnter Data\n\n"; // Prompt user for data
cin.getline(my_string, 81); // Reads data and tells max elements
cout << my_string << "END\n"; // Displays sting entered by user

/* Tells the size of the input */
string str (my_string);
cout << "The length of my_string is " << str.length() << " characters.\n";

reverse = reverse (const string& my_string);
cout << "The string in reverse looks like this...\n";
cout << reverse << "\n";

return 0;
}

/**************** Interchanges values of v1 and v2 *******************/
void swap(char& v1, char& v2)
{
char temp = v1;
v1 = v2;
v2 = temp;
}
/*********************************************************************/

/************ Returns a copy of my_string in reverse order ***********/
string reverse(const string& my_string)
{
int start = 0;
int end = str.length();
string temp(my_string);

while (start < end)
{
end--;
swap(temp[start], temp[end]);
start++;
}
return temp;
}
/********************************************************************/


Topic archived. No new replies allowed.