Well the sorting isnt the problem. The problem is whenever I go to do it again in a loop I guess the buffer is still open and it doesn't work. Here's the code and Id appreciate some help please.
#include <iostream>
#include <string>
#include <stack>
usingnamespace std;
/*
*
*/
void reverse(string& x) {
stack<char> s;
constint n = x.length();
//Put characters from x onto the stack
for(int i=0; i<n; ++i){
s.push(x[i]);
}
//take characters off of stack and put them back into x
for(int i=0; !s.empty(); ++i, s.pop()){
x[i]=s.top();
}
}
int main() {
int go =1;
char* s = (char *)malloc(80);
while(go == 1){
cout << "This program reverses a string using the STL stack" << endl;
cin.getline(s,81,'\n');
string word(s);
reverse(word);
cout << word << endl;
cout << "Enter another? 1 = continue. Anything else to stop" << endl;
cin >> go;
}
return 0;
}