I am trying to reverse a char array in C++. Here is my code :
void reverse(char s[]);
int main()
{
char s [] = "Harry";
cout << reverse(s) << endl;
system("PAUSE");
return 0;
}
void reverse(char s[])
{
if( strlen( s ) > 0 ) {
char* first = &s[ 0 ];
char* last = &s[ strlen( s ) - 1 ];
while( first < last ) {
char tmp = *first;
*first = *last;
*last = tmp;
++first;
--last;
}
return;
}
However, I got an error at cout << reverse(s) << endl; that line which located in main method and I have no idea why.The error message is no operator match these operands. Anybody can help me fix this?
Thanks in advance.