Reverse a string - C ++ program:
Write a program in c to reverse a string.
int main()
{
Stack theStack;
String reverse("reverse");
cout << "\nEnter some strings. Reverse will collect the strings\n";
cout << "for you until you enter the string \"reverse\". Reverse\n";
cout << "will then print out the strings you have entered, but in\n";
cout << "reverse order. Begin entering strings now.\n";
for(;;)
{
char inputString[255];
cin >> inputString;
String& newString = *( new String( inputString ) );
if( newString != reverse )
{
theStack.push( newString );
}
else
{
break;
}
}
cout << "\nThe strings you entered (if any) are:\n";
while( !(theStack.isEmpty()) )
{
Object& oldString = theStack.pop();
cout << oldString << "\n";
delete &oldString;
}
return 0;
}