title: Passing integer through a pipe
body: <p>I have problem sending an integer or array of integer through a pipe n Linux, first I was trying to send an integer, look at this code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include&lt;iostream&gt;
  #include&lt;cstdlib&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  using namespace std;
  
  int main()
  {
  
      int count = 10 ;
      //cout &lt;&lt;"Enter a digit : ";
      //cin &gt;&gt; count ;
      cout&lt;&lt;"\n";
  
      int pfd1[1];
      pipe(pfd1);    
  
      int a=fork();
      if(a==0)
      {    
          close(pfd1[0]);
          write(pfd1[1],&amp;count,sizeof(count));
          close(pfd1[1]);
          exit(0);
      }
      else
      {   
          wait(NULL);
          int n =0;
          close(pfd1[1]);       
          read(pfd1[0],&amp;n ,sizeof(n));
          close(pfd1[0]);
          cout &lt;&lt;"N from parent = "&lt;&lt;n&lt;&lt;"\n\n";
      }
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>N from parent = 4
  </code></pre>
  
  <p>The output should be <code>10</code> same as the one declared, but it gives me <code>4</code>, and even if I un-comment the comment code so the user enter a number, the output is always <code>4</code>, while it should be the number which the user entered.</p>
  
  <p>What is wrong here? And what if I want to send array of integers?</p>