C ++ Reverse Array
В C ++ мне нужно:
Read in a string from user input and place it into a char array [done] Then pass that array to a function [done] The function is supposed to reverse the order of characters [problem!] Then, back in themain()
, it displays that original array with the newly reversed characters.
У меня возникли проблемы с созданием функции, которая фактически выполняет реверсирование, потому что у меня есть некоторые ограничения:
I cannot have any local array variables. No pointers eitherМоя функция только передает в исходный массив, т.е.
void reverse(char word[])
EDIT: Вот моя база кода:
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--;
}
}