title: Dynamically allocate memory for C-string without first asking user how long input will be
body: <p>Still learning, in a C++ class. <br/>
   We are going over dynamic memory allocation, C-strings, and pointers. In this current assignment we are to use a pointer to a C-string and dynamically allocate just enough memory to store all the characters entered by the user PLUS the ‘\0’ char that must be appended at the end of the C-string. <br/>
  In the examples I'm seeing, a user is first asked how long their entry will be, then that number is used to allocate memory for the input. <br/>
  Example (just a code snippet):</p>
  
  <pre><code>int main(){ 
  double *sales = nullptr;
  int count;
  
  //User is first asked how long input will be.
  cout &lt;&lt; "For how many days do you want to enter sales? ";
  cin &gt;&gt; numDays;
  cout &lt;&lt; endl;
  
  sales = new double[numDays]; //numDays is now used to allot memory
  
  ...
  return(0);
  }
  </code></pre>
  
  <p>Other examples are similar in first asking the user how long the memory allotment should be. However, for this assignment we are to simply ask the user for direct C-string input. <br/>
  My question is, if we must store the input in a C-string array, we have to declare the size of the array with a constant which means we have to know more or less at compile time how much space we'll need, ya? This seems odd since the benefit of dynamic memory allocation is that 'how much memory space' is determined at run time, not compile time. <br/></p>
  
  <pre><code>int main()
  {
      const int SIZE = 10000;
      char inputArray[SIZE];
      char *inputPtr = nullptr;
      int inputLength = 0;
  
      cout &lt;&lt; "Enter some stuff and I'll show you the vowels." &lt;&lt; endl;
      cin.getline(inputArray, SIZE - 1);
  
      for (int i = 0; i &lt; SIZE; i++)
      {
          if (inputArray[i] == '\0')
          {
              inputLength = i - 1;
          }
      }
  
      inputPtr = new char[inputLength];
      inputPtr = inputArray;
  
  ...
  return(0);
  }
  </code></pre>
  
  <p>In my code above (I'm not sure I assigned the pointer correctly), I capture user input into an array that can hold 9,999 chars and '\0'. If the user types 'hi', then there's 9,997 nulls sitting in memory, ya? Is there a way to capture user input without the wasted space? <br/>
  The restrictions on this assignment are we can not use string variables, only C-strings. We can only use <code>new</code> and <code>delete</code> for dynamic memory allocation.</p>