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

#define SIZE 26


main()
{
  	int i,count,fd;
	char buf[SIZE];
	char ch = 'a'; 

	//pipe
	int fda[2];

	//if((fd = open("shared", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
	if(pipe(fda) == -1)
		printf("Error 1\n");

	
	if(fork()) //parent because it is the parent who call fork()
	{
	
		while (1){	
			ch = 'a';
			for(i = 0; i < 26;ch++,i++)
				buf[i] = ch;

			if(write(fda[1],buf,SIZE) != SIZE)
				printf("Error 2\n");
 		}
		close(fda[0]);
	}
	else
	{
		for (;;)
		{
			if(read(fda[0],buf,SIZE) == -1)
				printf("Error 3\n");
		
			for(i = 0; i < SIZE; i++)
				printf("%c",buf[i]);
		}
		close(fda[1]);
	}
	close(fd);
}

