// Problems.cpp : A place to try out little programming problems
//

#include "stdafx.h"

#include <iostream>

using namespace std;

/**
 * \brief Reverses a string, in place
 * \param *pStr - input string
 */
void RevStringInPlace(char *pStr)
{
	int length = (int)strlen( pStr );

	// loop through half of the string and swap start and end characters,
	// moving inwards towards the middle
	for (int i=0; i < length / 2; i++)
	{
		int offset = length - 1 - i;

		// swap characters at start and end positions
		pStr[i] = (char)(pStr[i] ^ pStr[offset]);
		pStr[offset] = (char)(pStr[i] ^ pStr[offset]);
		pStr[i] = (char)(pStr[i] ^ pStr[offset]);
	}
}

/**
 * \brief Main program loop.. you know the drill
 * \param argc - number of arguments
 * \param argv[] - array arguments
 * \return - success
 */
int _tmain(int argc, _TCHAR* argv[])
{
	char instr[] = "My old man is a caravan";

	cout << "Input string is: " << instr << endl;
	RevStringInPlace(&instr[0]);
	cout << "Output string is: " << instr << endl;


	return 0;
}

