In C++, I need to read in a string from user input and place it into a char array [done]
Then, I need to pass that array to a function [done]
That function is supposed to reverse the order of characters [problem!]
Then after, back in the main(), it displays that original array with the newly reversed characters.
I'm having trouble creating the function that actually does the reversing because I have some restrictions:
- I cannot have any local array variables.
- No pointers either
My function is only passing in the original array (ie:
void reverse(char word[])
EDIT: So far he has
void reverse(char word[]);
void main()
{
char word[MAX_SIZE];
cout << endl << "Enter a word : ";
cin >> word;
cout << "You entered the word " << word << endl;
reverse(word);
cout << "The word in reverse order is " << word << endl;
}
void reverse(char myword[])
{
int i, temp;
j--;
for(i=0;i<(j/2);i++)
{
temp = myword[i];
myword[i] = myword[j];
myword[j] = temp;
j--;
}
}
HELP please!!