title: How to declare an empty char* and increase the size dynamically?
body: <p>Let's say I am trying to do the following (this is a sub problem of what I am trying to achieve):</p>
  
  <pre><code>int compareFirstWord(char* sentence, char* compareWord){
        char* temp; int i=-1;
        while(*(sentence+(++i))!=' ') { *(temp+i) = *(sentence+i); }
        return strcmp(temp, compareWord); }
  </code></pre>
  
  <p>When I ran <code>compareFirstWord("Hi There", "Hi");</code>, I got error at the copy line. It said I was using temp uninitialized. Then I used <code>char* temp = new char[];</code> In this case the function returned 1 and not 0. When I debugged, I saw temp starting with some random characters of length 16 and <code>strcmp</code> fails because of this.</p>
  
  <p>Is there a way to declare an empty char* and increase the size dynamically only to length and contents of what I need ? Any way to make the function work ? I don't want to use <code>std::string</code>.</p>