title: How to pass arguments from child thread to grandchild thread in c
body: <p>I have this assignment where we have to create a child thread and grandchild thread. My childthread reads the input then my grandchild thread is supposed to convert the input it gets from the child thread to an array of integers. How do I manage to have child thread to communicate with grandchild thread. Do I need to create a private variable inside input or what??</p>
  <pre><code>#include&lt;iostream&gt;
  #include&lt;unistd.h&gt;
  #include &lt;bits/stdc++.h&gt;
  #include &lt;iostream&gt;
  #include &lt;sys/wait.h&gt; 
  using namespace std;
  
  struct thread_readInput {
     long long input;
  };
  struct thread_print {
     int  index;
    int *array;
    string *print;  
    int arraySize;
    long long input;
  };
  struct thread_print *print =  (struct thread_print *) print; 
  struct thread_readInput *count_digit =  (struct thread_readInput *) count_digit; 
  void* printArray(void *threadarg)
  {
     std::cout&lt;&lt;&quot;inside print array&quot; &lt;&lt; std::endl;
     // I want some how pass the input from readInput function 
     // to convert the input to an array
  
  }
  
  
  void* readInput(void *countArg)
  {
     struct thread_readInput *count_digit =  (struct thread_readInput *) countArg; 
     std::cout&lt;&lt;&quot;inside readInput array&quot;&lt;&lt; std::endl;
     int numberSize = 0;
     while (count_digit-&gt;input != 0)
     {
        count_digit-&gt;input  = count_digit-&gt;input  / 10;
        ++numberSize;
     }
     pthread_t inputThreads[numberSize];
     struct thread_print inputTd[numberSize];
  
     for( int i = 0; i &lt;numberSize; i++ )
     {
        inputTd[i].index=i;
        inputTd[i].input=count_digit-&gt;input;
        
        //tds[i].print = myStrings;
        if (pthread_create(&amp;inputThreads[i], NULL, printArray, &amp;inputTd[i]))
        {
           cout &lt;&lt; &quot;Error:unable to create thread,&quot; &lt;&lt; endl;  
        }
     }
     for( int i = 0;i&lt;numberSize;i++)
     {
        pthread_join(inputThreads[i], NULL);
     }
  }   
  
  
  
  
  int main(void){
      unsigned long long input; 
      cin &gt;&gt; input ;
  
     #define NUM_THREADS count_digit  
     pthread_t threads;
     struct thread_readInput td;
     td.input=input;
  
     if (pthread_create(&amp;threads, NULL, readInput, &amp;td)) 
        cout &lt;&lt; &quot;Error:unable to create thread,&quot; &lt;&lt; endl;   
     pthread_join(threads, NULL);
     //delete[] reversed_array;
     return 0;
  }
  </code></pre>