在 C++ 中,我需要:
- 从用户输入中读取字符串并将其放入 char 数组 [完成]
- 然后将该数组传递给函数[完成]
- 该函数应该颠倒字符的顺序[问题!]
- 然后,回到 中
main()
,它显示带有新反转字符的原始数组。
我无法创建实际执行反转的函数,因为我有一些限制:
- 我不能有任何本地数组变量。
- 也没有指针
我的函数只传入原始数组,即:
void reverse(char word[])
编辑:到目前为止,这是我的代码库:
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--;
}
}