Here's a working example of how to reverse a string using a function. Hope this helps, good luck!
#include <iostream>
using namespace std;
void ReverseString(char string1[], char reversed[]);
int main()
{
const int MAX = 80;
char string1[MAX];
char reversed[MAX];
cout << "Enter your string: ";
cin.get(string1,MAX);
ReverseString(string1, reversed);
return 0;
}
void ReverseString(char string1[], char reversed[])
{
int length = strlen(string1);
for (int i=length-1, j=0; i>=0; i--, j++)
reversed[j] = string1[i];
for (i=0; i<length; i++)
cout << reversed[i];
cout << endl;
}
You really should compile and test your code before posting. It contains several bugs that may just confuse the OP.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,957 posts
since Aug 2005