I have write this code. It does not show any error but string is not reversed.please let me know where i have made the mistake? I'm using codeblock to write code and GCC compiler. I have created two functions reverseString and printString, the printString function is working but reverseString is not working. what can i do?
#include <iostream>
#include<string>
using namespace std;
void reverseString(string s, int iNode, int lNode){
while(iNode < lNode){
char temp = s[iNode];
s[iNode] = s[lNode];
s[lNode] = temp;
iNode++;
lNode--;
}
}
void printString(string s, int n){
for(int i=0; i<n; i++){
cout << s[i];
cout << endl;
}
}
int main() {
string s;
cout << "Type String To Reverse: \n";
cin >> s;
cout << "String In Actual Order: \n";
printString(s,s.length());
reverseString(s, 0, s.length()-1);
cout << "String In Reverse Order: \n";
printString(s,s.length());
return 0;
}