#include<iostream>
using namespace std;
char* Invert(char* input,int start,int end);
char* reversewords(char* current);
int main(){
char inputstr[] = "London is a city";
cout << "Inverted string : " << Invert(inputstr,0,strlen(inputstr)) << endl;
int start,end ,i;
while(*inputstr){
if (*inputstr == ' ' || *inputstr == '\0')
{
Invert(inputstr,start,end);
start = i+1;
}
i++;
end = i;
(*inputstr++);
}
cout << "Inverted string : " << inputstr << endl;
}
char* Invert(char* input,int start,int end){
char* current = input;
int len = strlen(current);
char temp;
for (int i=start, j=end-1; i<=j; i++,j--)
{
temp = *(current+j);
*(current+j) = *(current+i);
*(current+i) = temp;
}
return input;
}
Above is the code that I've written so far to reverse a string but keep words as it is.
for ex: "London is a City" --> "City a is London"..
Approach that I've followed is
1. Reverse entire string
2. scan character by character, when hit a space or null, reverse that word.
I am getting following error on line 21 : (*inputstr++);
error: lvalue required as left operand of assignment
whats not right in my code? please help!