#include #include //#include using namespace std; //function prototypes void get_sentence(char[], int); int create_sentence(char*&); void dyn_sent(char*&, char); int main() { //define local variables char sentence[20]; char *sent2, *sent3; int length; char in; //create the second array based on user defined length length = create_sentence(sent2); //get the first two sentences get_sentence(sentence, 20); get_sentence(sent2, length); //print the first two arrays cout << sentence << endl; cout << sent2 << endl; //delete arrays //delete[] sentence; //sent2 = NULL; delete[] sent2; //initialize the third array to one character sent3 = new char[1]; //while the last charcter entered isnt new line, add the character to the array cout << "Enter the third sentence: "; do { cin.get(in); dyn_sent(sent3, in); //cout << sent3 << endl; } while(in != '\n'); cout << sent3 << endl; //finish up deleting //sent3 = NULL; delete[] sent3; return 0; } void get_sentence(char s[], int size) { cout << "Enter a string: "; cin.getline(s, size); } int create_sentence(char *&sent) { //cin.ignore(); int size; cout << "How long of a sentence do you want?: "; cin >> size; cin.ignore(); sent = new char[size]; //sent = NULL; //delete[] sent; return size; } void dyn_sent(char *&sent, char in) { int newSize = strlen(sent)+1; char *nextArray = new char[newSize]; for(int i=0; i < strlen(sent); i++) { nextArray[i] = sent[i]; } nextArray[newSize-1] = in; delete[] sent; //sent = new char[newSize]; sent = nextArray; //this messes stuff up //delete[] nextArray; }