title: how to return an array from a pthread
body: <p>I've been trying to get an array of ints back from a thread. I think I'm really close. The errors I'm getting are about dereferencing a void pointer and invalid use of a void expression here</p>
  
  <p>assn3.c:29:29: error: dereferencing ‘void *’ pointer [-Werror]</p>
  
  <pre><code>printf(" %d", (int)answer[j]);
                           ^
  </code></pre>
  
  <p>assn3.c:29:18: error: invalid use of void expression</p>
  
  <pre><code>printf(" %d", (int)answer[j]);
  </code></pre>
  
  <p>I've tried changing the return type of my functions to int* but it didn't seem to like that. What am I missing here?</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void *getFactors(void *param);
  
  int main(int argc, char *argv[])
  {
      for(int i = argc; i &gt; 0; i--)
      {
              void *answer;
              pthread_t tid;
              pthread_attr_t attr;
              if (atoi(argv[i])&lt;0)
              {
                      fprintf(stderr, "%d must be &gt; 0\n", atoi(argv[i]));
                      return -1;
              }
  
              pthread_attr_init(&amp;attr);
              pthread_create(&amp;tid, &amp;attr, getFactors, argv[i]);
              pthread_join(tid, &amp;answer);
  
              printf("%d", atoi(argv[i]));
              printf(":");
  
              for(int j = 0; j &lt; sizeof(answer); j++)
              {
                      printf(" %d", (int)answer[j]);
              }
              printf("\n");
      }
  }
  </code></pre>
  
  <p>And the thread function</p>
  
  <pre><code>void *getFactors(void *param)
  {
      int a[10];
      int n = atoi(param);
  
      int i = 0;
      while (n%2 == 0)
      {
              a[i] = 2;
              n/=2;
              i++;
      }
      int f=3;
      while (f * f &lt;= n)
      {
              if (n % f == 0)
              {
                      a[i]=f;
                      n /= f;
                      i++;
              }
              else
              {
                      f += 2;
              }
      }
      if (n&lt;1)
      {
              a[i]=n;
              i++;
      }
  
      int* buffer = (int*) malloc(i);
      buffer = a;
      return (void *) buffer;
  
      pthread_exit(0);
  }
  </code></pre>