// Utility to reverse a string of characters provided by
// the user on the command-line and print the result.
#include <iostream>

void swap( char* front, char* back )
{
    char temp = *front;
    *front = *back;
    *back = temp;
}

int main( int argc, char* argv[] )
{
    if ( argc != 2 ) {
        // Incorrect number of command-line arguments:
        std::cout << "\tUsage:\n\t\t" << argv[ 0 ] << " TEXT\n";
        return 1;
    }

    // Create a placeholder for the text to process:
    char buffer[ 1024 ] = {0};
    strcpy( buffer, argv[ 1 ] ); // copy source text into the buffer

    // A couple of pointers to point to the beginning and ending
    // of the string that is about to be reversed:
    char* pfront = buffer;
    char* pback = buffer + strlen( buffer ) - 1;

    // Do the required work: swap pairs of characters pointed
    // by pfront and pback pointers:
    while ( pfront < pback ) {
        swap( pfront, pback );
        ++pfront; // Move front pointer forward
        --pback;  // Move back pointer backward
    }

    // Display the result and exit:
    std::cout << buffer;
    return 0;
}

