Monday, 30 April 2012

Reversing the String in C++


#include <iostream>

using namespace std;
int main()
{
  char array[81];
  char* cptr = array;

  cout << "Enter a array of characters:" << endl << endl;
  cin.getarray(array, 81);

  while ( *cptr != '\0' )
  {
    ++cptr;
  }
  --cptr;
  cout << endl;
  cout << "The array in reverse is:" << endl << endl;
  while ( cptr != array )
  {
    cout << *cptr;
    --cptr;
  }
  cout << *cptr;
  cout << endl;
  return 0;
}


No comments:

Post a Comment