Sorry for the lack of comments, but it's not too complicated. I need to make a function that reverses a string inputed by the user. This is what I have so far, and I'm still learning C++, but I can't solve my problem:
// PROJECT 10-1.CPP
// By Josh Milewski
#include <iostream.h>
char original_string[21], reversed_string[21];
int x;
int reverse_string(int original_string)
{
for (x = 0; x < 21; x++)
{
reversed_string[x] = original_string[21-x];
}
return reversed_string[x];
}
main()
{
cout << "Input a string to be reversed: ";
cin.get(original_string, 21);
cout << '\n';
reversed_string[21] = reverse_string(original_string[21]);
cout << reversed_string[x] << '\n';
return 0;
}
In Microsoft Visual C++ 6.0, it says this when I try to compile it:
--------------------Configuration: PROJECT 10-1 - Win32 Debug--------------------
Compiling...
PROJECT 10-1.CPP
X:\PROJECT 10-1.CPP(13) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
PROJECT 10-1.OBJ - 1 error(s), 0 warning(s)
Please help me! Thank you very much!



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.