title: pipe example between multiple child-process in C
body: <p>When I working on pipe() function in C, I have confused a bit. My aim is to transfer data between child processes. I want each child to take an input from <code>fd[0]</code> and write to <code>fd[1]</code>. My code is here, but I couldnt obtain any result. Where is the mistake? How can I imagine pipe?</p>
  
  <pre><code>    int main()
      {
  
      char *arr = malloc(sizeof(int));
      int num;
      int fd[2];
      char *piping = malloc(10*sizeof(char));
      char *word = malloc(10*sizeof(char));
  
      while(1)
      {
          printf("enter the number of child: ");
          fflush(stdout);
          fgets(arr, 10, stdin);
  
          printf("enter word: ");
          fflush(stdout);
          fgets(word, 10, stdin);
  
          num = atoi(arr);
  
          pipe(fd);
          for(int i = 0; i &lt; num; i++)
          {
                  if(!fork())
                  {
                          read(0, piping, 10);
                          if(i != 0)
                          {   
                              dup2(fd[0],0);
                          }
                          if(i != num-1)
                          {
                              dup2(fd[1],1);
                          }
                          write(1, piping, 10);
                  }
                  else
                      wait(0);
          }
      }   
      return 0;
     }
  </code></pre>