title: Pipe 2 string using read/write after fork
body: <p>I´m having troubles to understand how pipes and fork work together for a online course. Firstly, I want to type two strings below a printf and the when all read/write end cat both string into one.
  I´m stuck in the read/write for both childs, the problems is that it didn´t match what I want because first print the strings and then open the channel to type. Maybe this is a small matter but I am starting using C for a online course. read and write function are compulsory.</p>
  <pre><code>String 1: 
  sdfsdfsdf
  String 2: 
  Sdfsdfdsfsdfsd
  String cat:
  sdfsdfsdfSdfsdfdsfsdfsd
  </code></pre>
  <p>here is my code so far.</p>
  <pre><code>int main()
  {
      int fd1[2],fd2[2];
      int status, pid;
      pipe(fd1);
      printf(&quot;String 1: \n&quot;);
      pid = fork();
      if(pid == 0)              /* child 1*/
      {
          close(fd1[0]);
          char cad1[100];
          read(0,&amp;cad1,100);
          write(fd1[1],&amp;cad1, 100);
          close(fd1[1]);
          exit(0);
      }
      else                          /* father*/
      {
          close(fd1[1]);
          printf(&quot;String 2: \n&quot;);
          pipe(fd2);
          pid = fork();
          if(pid == 0)               /* child 2 */
          {
              close(fd2[0]);
              close(fd1[0]);
              char cad2[100];
              read(0,&amp;cad2,100);
              write(fd2[1],&amp;cad2, 100);
              close(fd2[1]);
              exit(0);
          }
      }
      close(fd2[0]);
      /* wait every child */
      wait(&amp;status);
      wait(&amp;status);
      return 0;
  }
  </code></pre>
  <p>My output is like this:</p>
  <pre><code>String 1: 
  String 2: 
  cvbcvbcvbcvb
  cvbcvbcvbcvb
  </code></pre>
  <p>To cat my code (not implemented in the code I think to call both pipe into to char [] variable before cat.</p>
  <p>Any suggestion to improve my code.
  Thanks in advance.</p>