title: Efficient Memory allocation and freeing question
body: <p>I am writing a program that prints a string having been removed white space.</p>
  <p>At this time, in the <code>removeWhiteSpace</code> function, I would like to know if memory allocation and freeing are used efficiently.</p>
  <p>If not, can you suggest appropriate improvements:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  char *removeWhiteSpace();
  
  int main()
  {
      char *inputString = malloc(sizeof(char) * 100);
      
      scanf(&quot; %[^\n]s&quot;, inputString);
      
      removeWhiteSpace(inputString);
      
      printf(&quot;%s\n&quot;, inputString);
      
      free(inputString);
      
      return 0;
  }
  
  char *removeWhiteSpace(char *inputString)
  {
      char *tempArray = malloc(sizeof(char) * 100);
      char *tempPointer = strtok(inputString, &quot; &quot;);
      
      while (tempPointer != NULL)
      {
          strcat(tempArray, tempPointer);
          tempPointer = strtok(NULL, &quot; &quot;);
      }
      
      strcpy(inputString, tempArray);
      
      free(tempArray);
      
      return tempArray;
  }
  </code></pre>