#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#define SIZE 26

main()
{
  int i=0, count=0, fd, fda[2];
  char buf[SIZE];
  char ch='a';
  
  if(pipe(fda)==-1)
  {
       printf("Error creating pipe\n");
  }
  
  if(fork())  // parent process
  {
       close(fda[0]);  // empeche de lire pendant que l'on ecrit
       while(1)
       {
           for(i=0; i<26; i++)
           {
                buf[i]=i+ch;
           }
           if(write(fda[1], buf, SIZE) != SIZE)
           {
                printf("Error writing to file\n");
           }
       }
       close(fda[0]);
 }
 else  // child process
 {
     close(fda[1]);
     for(;;)
     {
         if((read(fda[0],buf,SIZE))==-1)
         {   
              printf("Error reading file\n");
         }      
              for(i=0; i<26; i++)
              {
                   printf("%c", buf[i]);
              }
     }
     close(fda[1]);   
 }
}
