/* The client's program */

#include <stdio.h>
#include <stdlib.h>      // exit
#include <unistd.h>
#include <fcntl.h>       // open

int main() {
  char buf[BUFSIZ];
  int fd,n;
  
  /* open FIFO for writing */

  fd = open("/tmp/pipe", O_WRONLY);

  printf("FIFO opened\n");

  if (fd < 0 ) 
    {
      perror("Open");
      exit(1);
    }
  
  /* read data from standard input and write to FIFO */

  printf("Type in some characters and press Enter\n");

  while ((n=read(0,buf,BUFSIZ-1)) > 0) 
    {
      buf[n]=0;

      if (write(fd,buf,n) < 0)
	exit(1);
 
     printf("Data written: %s\n",buf);
     printf("Type in some characters and press Enter\n");
    }
  
  close (fd);
  
  exit(0);
}
