title: struct pointers in c doesn't return correct value
body: <p>I have this program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #niclude ......
  
  struct sort {
      char  * array;
      int left,right;
  };
  
  void quicksortthread(struct sort *s){
      int left, right;
      int i, j, x, tmp;
      pthread_t *th1, *th2;
      char * v;
      struct sort s1;
      struct sort s2;
  
      left = s-&gt;left;
      right = s-&gt;right;
  
      v = s-&gt;array;
  
      printf("\n\n\n\n QT: l=%i, r=%i \n",left,right);
  
      //sorting algorithm
      if (left &gt;= right)
          return;
      x = v[left];
      i = left - 1;
      j = right + 1;
      while (i &lt; j) {
          while (v[--j] &gt; x);
          while (v[++i] &lt; x);
          if (i &lt; j) {
              char temp = v[i];
              v[i] = v[j];
              v[j] = temp;
          }
      }
  
      s1.array = v;
      s1.left = left;
      s1.right = j;
      s2.array = v;
      s2.left = j+1;
      s2.right = right;
      printf("1)left = %i; right= %i\n", left,j);
      printf("2)left = %i; right= %i\n", j+1,right);
      pthread_create(&amp;th1, NULL, quicksortthread,&amp;s1);
      pthread_create(&amp;th2, NULL, quicksortthread,&amp;s2);
  }
  
  int main (int argc, char ** argv){
  
      pthread_t *th1;
      int fd, len, pg, i, j;
      int left, right;
      struct stat stat_buf;
      char c, *paddr;
      struct sort s;
  
      /*..LOTS OF THIGS
  
        Define right and left as integers and
        paddr as a char *
  
        ..*/
  
      if(   (right)   &gt;=  (atoi(argv[2]))  ){
  
          //printf("filling structure\n");
          s.array = paddr;
          s.left = left;
          s.right = right;
          //printf("creating threads\n");
          pthread_create(&amp;th1, NULL, quicksortthread,&amp;s);
      }
  
      sleep(100);
  }
  </code></pre>
  
  <p>After two thread calls it stops working. It is because the structure passed in the function <code>pthread_create</code> as a last parameter, seems like incorrect. It compiles and it execute without (for e.g.) segmentation fault. I am sure that I am using in the correct way structures and pointers.</p>
  
  <p>Then the program returns in this way:</p>
  
  <pre><code>left = 0; right= 2048
  QT: l=0, r=2048 
  1)left = 0; right= 0
  2)left = 1; right= 2048    
  
  left = 0; right= 0
  QT: l=0, r=0 
  
  left = 1037061890; right= 32542
  QT: l=1037061890, r=32542 
  </code></pre>
  
  <p><strong>SOLVED:</strong> Ok I have solve this problem changing the thread routine in this way:</p>
  
  <pre><code>nt left, right;
  int i, j, x, tmp;
  pthread_t th1, th2;
  char * v;
  struct sort * s1;
  s1= malloc(sizeof(struct sort *));
  struct sort * s2;
  s2= malloc(sizeof(struct sort *));
  
  left =  s-&gt;left;
  right = s-&gt;right;
  printf("\n\n\n\nleft = %i; right= %i\n", left,right);
  v =  s-&gt;array;
  printf("QT: l=%i, r=%i \n",left,right);
  
  if (left &gt;= right)
  return;
  x = v[left];
  i = left - 1;
  j = right + 1;
  while (i &lt; j) {
  while (v[--j] &gt; x);
  while (v[++i] &lt; x);
  if (i &lt; j) {
  
     char temp = v[i];
     v[i] = v[j];
     v[j] = temp;
       }
   }
  
   s1-&gt;array = v;
   s1-&gt;left = left;
   s1-&gt;right = j;
   s2-&gt;array = v;
   s2-&gt;left = j+1;
   s2-&gt;right = right;
   printf("1)left = %i; right= %i\n", left,j);
   printf("2)left = %i; right= %i\n", j+1,right);
   pthread_create(&amp;th1, NULL, quicksortthread,s1);
   pthread_create(&amp;th2, NULL, quicksortthread,s2);
  </code></pre>