This is my attempt at taking an input and then produce an output with the words in the reverse order. Note: I can only use pointers.
Input: What is your name?
Output: name? your is What
I have looked at the other solutions posted here and thought tried to implement them as much as possible but I keep running into problems. Currently it only displays the first letter of the line. I would appreciate any help to fix it!
#include <iostream>
using namespace std;
#include <cstring>
int main( )
{
char input[255] = {' '};
char *head, *tail;
char temp;
int i = 0;
cin >> input;
head = input;
tail = input;
while(*tail!='\0')
{
tail++;
}
while (tail <= head){
temp = *head;
*head=*tail;
*tail=temp;
*head++;
*tail--;
}
cout << input;
cout << endl;
return 0;
}
Try this. Without anything referring STL.