title: How to malloc inside a function and return pointer in C?
body: <p>Below is some psudo, but I'm trying to accomplish this. The problem is as written, it returns a blank pointer.</p>
  
  <pre><code>int testFunction(char *t) {
      int size = 100;
      t = malloc(100 + 1);
      t = &lt;do a bunch of stuff to assign a value&gt;;
      return size;
  }
  
  int runIt() {
      char *str = 0;
      int str_size = 0;
      str_size = testFunction(str);
      &lt;at this point, str is blank and unmodified, what's wrong?&gt;
      free(str);
      return 0;
  }
  </code></pre>
  
  <p>This works fine if I have a predefined size, such as <em>char str[100] = ""</em> and I don't try to malloc or free memory afterwords. I need to be able to make the size dynamic though.</p>
  
  <p>I've also tried this, but seem to run into a corrupt pointer somehow.</p>
  
  <pre><code>int testFunction(char **t) {
      int size = 100;
      t = malloc(100 + 1);
      t = &lt;do a bunch of stuff to assign a value&gt;;
      return size;
  }
  
  int runIt() {
      char *str = 0;
      int str_size = 0;
      str_size = testFunction(&amp;str);
      &lt;at this point, str is blank and unmodified, what's wrong?&gt;
      free(str);
      return 0;
  }
  </code></pre>
  
  <p>Thanks!</p>