here is my code so far for those who would like some context to my previous post:
Code:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
void swap (char *front, char *rear);
using namespace std;
int main()
{
string input, word;
char *front, *rear;
char *p; // This will hold the individual words temporarily until they are replaced
cout << "Enter a sentence that you would like to reverse: ";
getline(cin, input);
// put the sentence into a stream
istringstream break_apart(input);
while (break_apart >> word)
{
front = &word.at(0);
rear = &word.at(word.size() - 1);
while (front <= rear)
{
swap (*front, *rear);
front++;
rear--;
}
cout << word << " ";
}
return 0;
}
void swap (char *front, char *rear)
{
char temp = *front;
*front = *rear;
*rear = temp;
}
If you didn't see my previous post, I would like to know how to create a dynamic array. Thank you to all who can help me, much appreciated!