title: Returning single integer value from thread
body: <p>I need help returning integer value from thread.  I have tried several things and can't get it to work.  I am new to C and yes this is homework, but I am stuck and need some help on this.  I have created the pointer in the thread but when I pass it back to main, it does not show the right value.  I have tried malloc and that does not work either.  Any tips would be appreciated.</p>
  
  <p>Here is the Code:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;math.h&gt;
  #include&lt;pthread.h&gt;
  #include "FindNextHigher.h"
  #include "SortNumber.h"
  
  void *thread_next(void *arg)
  {
     /* Call FindNextHigher */
     int *num =(int *)arg;
     int next = FindNextHigher(*num);
     printf("next= %d\n", next);
     /* Convert int to pointer to pass and print to check*/
     int *next_ptr=&amp;next;
     printf("nextptr= %d\n", *next_ptr);
     return (void *)next_ptr;
  }
  
  int main(int argc, char *argv[])
  {
     FILE* f = fopen(argv[1], "r");
     int i, num, *next_ptr;
     printf("next_ptr = %d\n", *next_ptr);
     pthread_t thread1, thread2, thread3, thread4;
     void *exit_status;
  
     for(i=1; i&lt;=20; i++)
     {
     fscanf(f, "%d", &amp;num);
     if (i==1 || i&lt;=60){
       pthread_create(&amp;thread1, NULL, thread_next, &amp;num);
       pthread_join(thread1, &amp;exit_status);
       printf("Threadid 1 processes number %d which is %d and the next higher number is %d\n", i, num, *next_ptr);
       if (i==60){
          printf("--------------Process finished for Thread 1----------");
          } 
       }
     else {
     if (i==61 || i&lt;=120){ 
       pthread_create(&amp;thread2, NULL, thread_next, &amp;num);
       pthread_join(thread2, &amp;exit_status);
       printf("Threadid 2 processes number %d which is %d and the next higher number is %d\n", i, num, *next_ptr);
       if (i==120){
          printf("--------------Process finished for Thread 2----------");
       }
     }
     else{
     if (i==121 || i&lt;=180){
       pthread_create(&amp;thread3, NULL, thread_next, &amp;num);
       pthread_join(thread3, &amp;exit_status);
       printf("Threadid 3 processes number %d which is %d and the next higher number is %d\n", i, num, *next_ptr);
       if (i==180){
          printf("--------------Process finished for Thread 3----------");
        }
     }
     else{
     if (i==181 || i&lt;=240){
       pthread_create(&amp;thread4, NULL, thread_next, &amp;num);
       pthread_join(thread4, &amp;exit_status);
       printf("Threadid 4 processes number %d which is %d and the next higher number is %d\n", i, num, *next_ptr);
       if (i==240){
          printf("--------------Process finished for Thread 4----------");
       }
     }
     }
     }
     }
     }    
     return 0;
  }
  </code></pre>