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

#define SIZE 26


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

	//pipe
	int fda[2];

	if(pipe(fda) == -1)
		printf("Error 1\n");

	
	if(fork()) //parent because it is the parent who call fork()
	{
		close(fda[0]);
		for(;;){	
			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
	{
		close(fda[1]);
		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]);
	}
}

