The code below runs fine but I want some help how can I get output of my original input and reverse of that i.e. ABCDE Z. WXYZ ---> EDCBA .Z ZYXW The below is the code for this.
#include <iostream>
#include <cstring>
using namespace std;
void swap(char& a, char& b)
{
char tmp = a;
a = b;
b = tmp;
}
int main()
{
char name[19] = "ABCDE Z. WXYX";
int a = -1, b = -1;
int nameLength = strlen(name);
for (int i = 0; i <= nameLength; ++i)
if (i == nameLength || name[i] == ' ')
{
b = i;
for (int j = 0; j < (b - a) / 2; ++j)
swap(name[j + a], name[b - j - 1]);
a = b + 1;
}
else
if (a == -1)
a = i;
cout << name <<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}