I am trying to reorder a C string backwards using pointers. In my program I take in the string and then in the for loops I rearrange it.
For example, if I input Thomas, then it should return samohT using pointers.
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int lengthString;
char name[256];
cout << "Please enter text: ";
cin.getline(name, 256);
cout << "Your text unscrambled: " << name << endl;
lengthString = strlen(name);
cout << "length " << lengthString << endl;
char* head = name;
char* tail = name;
for (int i = 0; i < lengthString; i++)
{
//swap here?
}
for (int j = lengthString - 1; j > -1; j--)
{
//swap here?
}
return 0;
}
What am I missing in those two loops?
EDIT :